/* This is a customised template.
 * It overrides some optional methods from EntityMap to allow for testing 
 * with Mocks and fast object creation. Search for #custom# below. 
 */


namespace CRMSample.Models
{

#region Using statements

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using Neo.Core;
using Expergent;
using Expergent.Neo;
using Neo.Core.Util;
using Neo.Framework;

#endregion

#region CustomerBase

/// <summary>
/// Generated table specific Base Class </summary>
/// <remarks> This class is generated by the Neo Framework. Make changes to NeoSupport.vtl.</remarks>
public partial class Customer : RulesEnabledEntityObject
{
	/// <summary>
	/// A collection of Order objects referencing this instance.</summary>
	/// <remarks> Objects referencing this instance.</remarks>
	public readonly ObjectRelation<Order> Orders;
       
	internal Customer(System.Data.DataRow aRow, Neo.Core.ObjectContext aContext) : base(aRow, aContext)
	{
		Orders = new ObjectRelation<Order>(this, "Orders");
	}
	
	/// <summary>
	/// Property CustomerID - No Description </summary>
	/// <remarks> Database Path: CRMSample.Customers.CustomerID.</remarks>
	/// <value> System.Int32. </value>
	public virtual System.Int32? CustomerID
	{
		get { object v = Row["CustomerID"]; return (System.Int32?)((v != DBNull.Value) ? v : null); }
		set { if (value.HasValue) Row["CustomerID"] = value; else Row["CustomerID"] = DBNull.Value; }
	}    

	/// <summary>
	/// Property Name - No Description </summary>
	/// <remarks> Database Path: CRMSample.Customers.Name.</remarks>
	/// <value> System.String. </value>
	public virtual System.String Name
	{
		get { return Row["Name"] as System.String; }
		set { Row["Name"] = (value != null) ? (object)value : (object)DBNull.Value; }
	}    

	/// <summary>
	/// Property MailingAddressID - No Description </summary>
	/// <remarks> Database Path: CRMSample.Customers.MailingAddressID.</remarks>
	/// <value> System.Guid. </value>
	public virtual System.Guid? MailingAddressID
	{
		get { object v = Row["MailingAddressID"]; return (System.Guid?)((v != DBNull.Value) ? v : null); }
		set { if (value.HasValue) Row["MailingAddressID"] = value; else Row["MailingAddressID"] = DBNull.Value; }
	}    

	/// <summary>
	/// Property DeliveryAddressID - No Description </summary>
	/// <remarks> Database Path: CRMSample.Customers.DeliveryAddressID.</remarks>
	/// <value> System.Guid. </value>
	public virtual System.Guid? DeliveryAddressID
	{
		get { object v = Row["DeliveryAddressID"]; return (System.Guid?)((v != DBNull.Value) ? v : null); }
		set { if (value.HasValue) Row["DeliveryAddressID"] = value; else Row["DeliveryAddressID"] = DBNull.Value; }
	}    

	/// <summary>
	/// Property StatusID -  $attribute.Description </summary>
	/// <remarks> Database Path: CRMSample.Customers.StatusID.</remarks>
	/// <value> System.Int32. </value>
	public virtual System.Int32? StatusID
	{
		get { object v = Row["StatusID"]; return (System.Int32?)((v != DBNull.Value) ? v : null); }
		set { if (value.HasValue) Row["StatusID"] = value; else Row["StatusID"] = DBNull.Value; }
	}    

	/// <summary>
	/// Property Remarks - No Description </summary>
	/// <remarks> Database Path: CRMSample.Customers.Remarks.</remarks>
	/// <value> System.String. </value>
	public virtual System.String Remarks
	{
		get { return Row["Remarks"] as System.String; }
		set { Row["Remarks"] = (value != null) ? (object)value : (object)DBNull.Value; }
	}    


	/// <summary>
	/// Property MailingAddress - gets or sets the Address object with a one-to-one relationship to this instance.</summary>
	/// <remarks> Property MailingAddress - gets or sets the Address object with a one-to-one relationship to this instance.</remarks>
	/// <value> Address. </value>
	public virtual Address MailingAddress
	{
		get { object fk = Row["MailingAddressID"]; return (fk == DBNull.Value) ? null : (Address)GetRelatedObject("Addresses", fk); }
		set { SetRelatedObject(value, "MailingAddressID", "AddressID" ); }
	}

	/// <summary>
	/// Property DeliveryAddress - gets or sets the Address object with a one-to-one relationship to this instance.</summary>
	/// <remarks> Property DeliveryAddress - gets or sets the Address object with a one-to-one relationship to this instance.</remarks>
	/// <value> Address. </value>
	public virtual Address DeliveryAddress
	{
		get { object fk = Row["DeliveryAddressID"]; return (fk == DBNull.Value) ? null : (Address)GetRelatedObject("Addresses", fk); }
		set { SetRelatedObject(value, "DeliveryAddressID", "AddressID" ); }
	}

	/// <summary>
	/// Property Status - gets or sets the Status object with a one-to-one relationship to this instance.</summary>
	/// <remarks> Property Status - gets or sets the Status object with a one-to-one relationship to this instance.</remarks>
	/// <value> Status. </value>
	public virtual Status Status
	{
		get { object fk = Row["StatusID"]; return (fk == DBNull.Value) ? null : (Status)GetRelatedObject("Status", fk); }
		set { SetRelatedObject(value, "StatusID", "StatusID" ); }
	}

	/// <summary>
	/// Returns the value associated with the propName parameter.</summary>
	/// <remarks> You will need to cast the returned object into its native type upon return.</remarks>
	/// <param name="propName">String property name.</param>
	/// <returns> System.Object. </returns>
	public override object GetProperty(string propName)
	{
		if(propName == "CustomerID") 
			return CustomerID;
		if(propName == "Name") 
			return Name;
		if(propName == "MailingAddressID") 
			return MailingAddressID;
		if(propName == "DeliveryAddressID") 
			return DeliveryAddressID;
		if(propName == "StatusID") 
			return StatusID;
		if(propName == "Remarks") 
			return Remarks;
		if(propName == "MailingAddress") 
			return MailingAddress;
		if(propName == "DeliveryAddress") 
			return DeliveryAddress;
		if(propName == "Status") 
			return Status;
		if(propName == "Orders") 
			return Orders;
		return ExtendGetProperty(propName);
	}
	
	/// <summary>
    /// Sets the value associated with the propName parameter to the value specified.
    /// </summary>
    /// <param name="propName">String property name.</param>
    /// <param name="value">The value.</param>
	public override void SetProperty(string propName, object value)
	{
		if(propName == "CustomerID") 
		{
			CustomerID = (System.Int32?)value;
			return;
		}
		if(propName == "Name") 
		{
			Name = (System.String)value;
			return;
		}
		if(propName == "MailingAddressID") 
		{
			MailingAddressID = (System.Guid?)value;
			return;
		}
		if(propName == "DeliveryAddressID") 
		{
			DeliveryAddressID = (System.Guid?)value;
			return;
		}
		if(propName == "StatusID") 
		{
			StatusID = (System.Int32?)value;
			return;
		}
		if(propName == "Remarks") 
		{
			Remarks = (System.String)value;
			return;
		}
		if(propName == "MailingAddress") 
		{
			MailingAddress = (Address)value;
			return;
		}
		if(propName == "DeliveryAddress") 
		{
			DeliveryAddress = (Address)value;
			return;
		}
		if(propName == "Status") 
		{
			Status = (Status)value;
			return;
		}
		ExtendSetProperty(propName, value);
	}

    /// <summary>
    /// Ensures related tables are loaded into memory for a cascaded delete.</summary>
    /// <remarks> Deletes related tables entries when cascade is specified.</remarks>
    public override void Delete() 
    {
        Orders.Touch();
        while (Orders.Count > 0)
        {
            Orders[0].Delete();
        }
        base.Delete();
    }

    /// <summary>
    /// Adds a set of facts for this instance to the list.
    /// </summary>
    /// <param name="list">The list.</param>
    /// <param name="parent">The parent.</param>
    protected override void MakeFacts(List<WME> list, string parent)
    {
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "CustomerID"), CustomerID));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "Name"), Name));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "MailingAddressID"), MailingAddressID));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "DeliveryAddressID"), DeliveryAddressID));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "StatusID"), StatusID));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "Remarks"), Remarks));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "MailingAddress"), MailingAddress));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "DeliveryAddress"), DeliveryAddress));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "Status"), Status));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "Orders"), Orders));
        ExtendMakeFacts(list, parent);
        myFactsHaveBeenAsserted = true;
    }

	/// <summary>
    /// Populates the EntityObject from the specified surrogate.
    /// </summary>
    /// <param name="surrogate">The surrogate.</param>
	public void Populate(CustomerSurrogate surrogate)
	{
		Name = surrogate.Name;
		MailingAddressID = surrogate.MailingAddressID;
		DeliveryAddressID = surrogate.DeliveryAddressID;
		StatusID = surrogate.StatusID;
		Remarks = surrogate.Remarks;
	}
}

#endregion

#region CustomerTemplate

/// <summary>
/// Generated table specific Query Template Class </summary>
/// <remarks> A Query Template for Customer operations. </remarks>
public class CustomerTemplate : QueryTemplate
{

	/// <summary>
	/// Constructor </summary>
	/// <remarks> Public Constructor.</remarks>
	/// <param name="anEntityMap">IEntityMap instance.</param>
	public CustomerTemplate(IEntityMap anEntityMap) : base(anEntityMap)
	{
	}
	
	/// <summary>
	/// Property CustomerID - No Description </summary>
	/// <remarks> Database Path: CRMSample.Customers.CustomerID.</remarks>
	/// <value> System.Int32. </value>
	public System.Int32 CustomerID
	{
		get { return (System.Int32)QueryValues["CustomerID"]; }
		set { QueryValues["CustomerID"] = value; }
	}

	/// <summary>
	/// Property Name - No Description </summary>
	/// <remarks> Database Path: CRMSample.Customers.Name.</remarks>
	/// <value> System.String. </value>
	public System.String Name
	{
		get { return (System.String)QueryValues["Name"]; }
		set { QueryValues["Name"] = value; }
	}

	/// <summary>
	/// Property MailingAddressID - No Description </summary>
	/// <remarks> Database Path: CRMSample.Customers.MailingAddressID.</remarks>
	/// <value> System.Guid. </value>
	public System.Guid MailingAddressID
	{
		get { return (System.Guid)QueryValues["MailingAddressID"]; }
		set { QueryValues["MailingAddressID"] = value; }
	}

	/// <summary>
	/// Property DeliveryAddressID - No Description </summary>
	/// <remarks> Database Path: CRMSample.Customers.DeliveryAddressID.</remarks>
	/// <value> System.Guid. </value>
	public System.Guid DeliveryAddressID
	{
		get { return (System.Guid)QueryValues["DeliveryAddressID"]; }
		set { QueryValues["DeliveryAddressID"] = value; }
	}

	/// <summary>
	/// Property StatusID -  $attributes.Description </summary>
	/// <remarks> Database Path: CRMSample.Customers.StatusID.</remarks>
	/// <value> System.Int32. </value>
	public System.Int32 StatusID
	{
		get { return (System.Int32)QueryValues["StatusID"]; }
		set { QueryValues["StatusID"] = value; }
	}

	/// <summary>
	/// Property Remarks - No Description </summary>
	/// <remarks> Database Path: CRMSample.Customers.Remarks.</remarks>
	/// <value> System.String. </value>
	public System.String Remarks
	{
		get { return (System.String)QueryValues["Remarks"]; }
		set { QueryValues["Remarks"] = value; }
	}

	/// <summary>
	/// Property MailingAddress - gets or sets the Address object with a one-to-one relationship to this instance.</summary>
	/// <remarks> Gets or sets the Address object.</remarks>
	/// <value> Address. </value>
	public Address MailingAddress
	{
		get { return (Address)QueryValues["MailingAddress"]; }
		set { QueryValues["MailingAddress"] = value; }
	}

	/// <summary>
	/// Property DeliveryAddress - gets or sets the Address object with a one-to-one relationship to this instance.</summary>
	/// <remarks> Gets or sets the Address object.</remarks>
	/// <value> Address. </value>
	public Address DeliveryAddress
	{
		get { return (Address)QueryValues["DeliveryAddress"]; }
		set { QueryValues["DeliveryAddress"] = value; }
	}

	/// <summary>
	/// Property Status - gets or sets the Status object with a one-to-one relationship to this instance.</summary>
	/// <remarks> Gets or sets the Status object.</remarks>
	/// <value> Status. </value>
	public Status Status
	{
		get { return (Status)QueryValues["Status"]; }
		set { QueryValues["Status"] = value; }
	}

               
}

#endregion

#region CustomerFactory

/// <summary>
/// Factory class for the creation of Customer objects.</summary>
/// <remarks> This class is generated by the Neo Framework. Make changes to NeoSupport.vtl.</remarks>
public class CustomerFactory : Neo.Framework.ObjectFactory
{

	/// <summary>
	/// Constructor requiring an ObjectContext parameter.</summary>
	/// <remarks> Main entry point for the retrieval and creation of new Customer objects.</remarks>
	/// <param name="context">ObjectContext.</param>
	public CustomerFactory(ObjectContext context) : base(context, typeof(Customer))
	{
	}

	/// <summary>
	/// Create new Customer object.</summary>
	/// <remarks>IdMethod = Native, PrimaryKeyIsForeignKey = False, RelationshipSetsForColumns = 1.</remarks>
	/// <returns> Customer </returns>
	public Customer CreateObject()
	{
		return (Customer)base.CreateObject(null);
	}
	

	/// <summary>
	/// Find a specified Customer object.</summary>
	/// <remarks> Requires Primary Key values and/or parent object instances.</remarks>
	/// <param name="arg0">.</param>
	/// <returns> Customer </returns>
	public Customer FindObject(System.Int32 arg0)
	{
		return (Customer)base.FindObject(new object[] { arg0 } );
	}

	///<summary>
	///Find a specified Customer object.</summary>
	///<remarks> Requires Primary Key values and/or parent object instances.</remarks>
	///<param name="arg0">.</param>
	///<returns> Customer </returns>
	public Customer FindObjectByPK( System.Int32 arg0 )
	{
		return (Customer) base.FindObject( new object[] {  arg0 } );
	}
	

	///<summary>
	///Find a specified Customer object.</summary>
	///<remarks> Requires Primary Key values and/or parent object instances.</remarks>
	///<param name="arg0">.</param>
	///<returns> Customer </returns>
	public Customer FindObjectByPK( System.Int32? arg0 )
	{
		return (Customer) base.FindObject( new object[] {  arg0.Value } );
	}

	/// <summary>
	/// Find a list of Customer objects.</summary>
	/// <remarks> Returns all.</remarks>
	/// <returns> ObjectList&lt;Customer&gt; </returns>
	public new ObjectList<Customer> FindAllObjects()
	{
		ObjectList<Customer> c = new ObjectList<Customer>();
		foreach(Customer eo in base.FindAllObjects())
			c.Add(eo);
		c.Sort("Name", SortDirection.Ascending);
		return c;
	}
	
	/// <summary>
	/// Return the correct Query Template for the Customer object.</summary>
	/// <remarks> A query template is used for creating SQL like queries, in a more OO fashion.</remarks>
	/// <returns> CustomerTemplate </returns>
	public CustomerTemplate GetQueryTemplate()
	{
		return new CustomerTemplate(EntityMap);
	}
	
	/// <summary>
	/// SQL like query to find and return a list of objects based on a template.</summary>
	/// <remarks> A query template is used for creating SQL like queries, in a more OO fashion.</remarks>
	/// <param name="template">CustomerTemplate.</param>
	/// <returns> ObjectList&lt;Customer&gt; </returns>
	public ObjectList<Customer> Find(CustomerTemplate template)
	{
		ObjectList<Customer> c = new ObjectList<Customer>();
		foreach(Customer eo in base.Find(template))
			c.Add(eo);
		return c;
	}

	/// <summary>
	/// SQL like query to find and return a list of objects based on a FetchSpecification.</summary>
	/// <remarks> A query Fetch Specification is used for creating SQL like queries, in a more OO fashion.</remarks>
	/// <param name="fetchSpecification">FetchSpecification.</param>
	/// <returns> ObjectList&lt;Customer&gt; </returns>
	public ObjectList<Customer> Find(FetchSpecification fetchSpecification)
	{
		ObjectList<Customer> c = new ObjectList<Customer>();
		foreach(Customer eo in base.Find(fetchSpecification))
			c.Add(eo);
		return c;
	}
	
	/// <summary>
	/// SQL like query to find and return a list of objects.</summary>
	/// <remarks> For example: ...Find("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> ObjectList&lt;Customer&gt; </returns>
	public new ObjectList<Customer> Find(string qualifierFormat, params object[] parameters)
	{
		ObjectList<Customer> c = new ObjectList<Customer>();
		foreach(Customer eo in base.Find(qualifierFormat, parameters))
			c.Add(eo);
		return c;
	}

	/// <summary>
	/// SQL like query to find and return a list of objects limiting the munber of items returned.</summary>
	/// <remarks> For example: ...Find(10, "TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="limit">Int32.</param>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> ObjectList&lt;Customer&gt; </returns>
	public new ObjectList<Customer> FindWithLimit(int limit, string qualifierFormat, params object[] parameters)
	{
		ObjectList<Customer> c = new ObjectList<Customer>();
		foreach(Customer eo in base.Find(qualifierFormat, parameters))
			c.Add(eo);
		return c;
	}
	
	/// <summary>
	/// SQL like query to find and return an object.</summary>
	/// <remarks> For example: ...FindFirst("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> Customer. </returns>
	public new Customer FindFirst(string qualifierFormat, params object[] parameters)
	{
		return (Customer)base.FindFirst(qualifierFormat, parameters);
	}

	/// <summary>
	/// SQL like query to find and return an object.</summary>
	/// <remarks> For example: ...FindUnique("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> Customer. </returns>
	public new Customer FindUnique(string qualifierFormat, params object[] parameters)
	{
		return (Customer)base.FindUnique(qualifierFormat, parameters);
	}	

	
}

#endregion

#region CustomerEntityMap

//  -------- Entity Map -----------------------------------------------------
/// <summary>Creates the in memory version of the dataset for the Customer DOM.</summary>
/// <remarks>Generated by Neo Framework.</remarks>
internal class CustomerMap : EntityMap
{
	  /// <summary>Array of Primary Key column names.</summary>
	  /// <remarks>Primary Key columns.</remarks>
    private static readonly string[] pkcolumns = { "CustomerID" };
    /// <summary>Array of Database column names.</summary>
	  /// <remarks>Database column names.</remarks>
    private static readonly string[] columns = { "CustomerID", "Name", "MailingAddressID", "DeliveryAddressID", "StatusID", "Remarks" };
    /// <summary>Array of DOM object properties.</summary>
	  /// <remarks>DOM object properties.</remarks>
    private static readonly string[] attributes = { "CustomerID", "Name", "MailingAddressID", "DeliveryAddressID", "StatusID", "Remarks" };
    /// <summary>Array of Related Object names.</summary>
	  /// <remarks>Related Object names.</remarks>
    private static readonly string[] relations = { "MailingAddress", "DeliveryAddress", "Status", "Orders" };

    private Type concreteObjectType = typeof(Customer);

	  /// <summary>Property ObjectType.</summary>
	  /// <remarks>Returns the DOM's Type.</remarks>
	  /// <value>System.Type.</value>
    public override System.Type ObjectType
    {
        get { return typeof(Customer); }
    }
    
    /// <summary>Property ObjectType.</summary>
	  /// <remarks>Returns the DOM's Type.</remarks>
	  /// <value>System.Type.</value>
    public override System.Type ConcreteObjectType
    {
        get { return concreteObjectType; }										 /* #custom# overridden */
        set { concreteObjectType = value; Factory.AddCustomType(value, this); }  /* #custom# overridden */
    }
    
    /// <summary>Property TableName.</summary>
	  /// <remarks>Returns database table name.</remarks>
	  /// <value>string.</value>
    public override string TableName
    {
        get { return "Customers"; }
    }
    
    /// <summary>Property PrimaryKeyColumns.</summary>
	/// <remarks>Array of Primary Key column names.</remarks>
	/// <value>string[].</value>
    public override string[] PrimaryKeyColumns
    {
        get { return pkcolumns; }
    }

	/// <summary>Property Columns.</summary>
	/// <remarks>Array of Database column names.</remarks>
	/// <value>string[].</value>
    public override string[] Columns
    {
        get { return columns; }
    }

	/// <summary>Property Attributes.</summary>
	/// <remarks>Array of DOM object properties.</remarks>
	/// <value>string[].</value>
    public override string[] Attributes
    {
        get { return attributes; }
    }

    /// <summary>Property Relations.</summary>
	/// <remarks>Array of Related Object names.</remarks>
	/// <value>string[].</value>
    public override string[] Relations
    {
        get { return relations; }
    }

	/// <summary>Generates a Hashtable, keyed by Object Name, or information regarding related objects.</summary>
	/// <remarks>Related Objects.</remarks>
	/// <returns>IDictionary.</returns>
  	protected override IDictionary GetRelationInfos()
    {
    	IDictionary infos = new Hashtable(4);
  		infos.Add("MailingAddress", new RelationInfo(Factory, typeof(Address), typeof(Customer), "AddressID", "MailingAddressID"));
 		infos.Add("DeliveryAddress", new RelationInfo(Factory, typeof(Address), typeof(Customer), "AddressID", "DeliveryAddressID"));
 		infos.Add("Status", new RelationInfo(Factory, typeof(Status), typeof(Customer), "StatusID", "StatusID"));
 		infos.Add("Orders", new RelationInfo(Factory, typeof(Customer), typeof(Order), "CustomerID", "CustomerID"));
		return infos;    	
    }
    
	/// <summary>Based upon the model specified Id Method, returns the proper PkInitializer.</summary>
	/// <remarks>The object used to create a new PK value.</remarks>
	/// <returns>IPkInitializer.</returns>
	public override IPkInitializer GetPkInitializer()
	{
		return new NativePkInitializer();
	}
    
	/// <summary>Creates a new instance of Customer.</summary>
	/// <remarks>Create new Customer.</remarks>
	/// <param name="row">DataRow.</param>
	/// <param name="context">ObjectContext.</param>
	/// <returns>IEntityObject.</returns>
    public override IEntityObject CreateInstance(DataRow row, ObjectContext context) /* #custom# overridden */
    {
		if(ConcreteObjectType != ObjectType)
			return base.CreateInstance(row, context);
		return new Customer(row, context);
	}
    
    /// <summary>Generates the in memory dataset.</summary>
	/// <remarks>Called by the Factory object.</remarks>
	/// <param name="table">DataTable.</param>
    protected override void WriteBasicSchema(DataTable table)
    {
		DataColumn		c;
		
		c = table.Columns.Add("CustomerID", typeof(System.Int32));
		c.Unique = true;
		c.AutoIncrement = true; c.AutoIncrementSeed = c.AutoIncrementStep = -1;
		c = table.Columns.Add("Name", typeof(System.String));
		c = table.Columns.Add("MailingAddressID", typeof(System.Guid));
		c = table.Columns.Add("DeliveryAddressID", typeof(System.Guid));
		c = table.Columns.Add("StatusID", typeof(System.Int32));
		c = table.Columns.Add("Remarks", typeof(System.String));
		table.PrimaryKey = new DataColumn[] { table.Columns["CustomerID"] };
	}
	
	/// <summary>Generates the dataset relationships.</summary>
	/// <remarks>Dataset Relationships.</remarks>
	/// <param name="table">DataTable.</param>
	protected override void WriteRelations(DataTable table)
	{
		DataRelation r;
		
		if(table.DataSet.Relations["Addresses*Customers.MailingAddressID"] == null)
		{
			r = table.DataSet.Relations.Add("Addresses*Customers.MailingAddressID", 
					table.DataSet.Tables["Addresses"].Columns["AddressID"],
					table.DataSet.Tables["Customers"].Columns["MailingAddressID"]);
			r.ChildKeyConstraint.UpdateRule = Rule.None;
			r.ChildKeyConstraint.DeleteRule = Rule.None;
		}
		if(table.DataSet.Relations["Addresses*Customers.DeliveryAddressID"] == null)
		{
			r = table.DataSet.Relations.Add("Addresses*Customers.DeliveryAddressID", 
					table.DataSet.Tables["Addresses"].Columns["AddressID"],
					table.DataSet.Tables["Customers"].Columns["DeliveryAddressID"]);
			r.ChildKeyConstraint.UpdateRule = Rule.None;
			r.ChildKeyConstraint.DeleteRule = Rule.None;
		}
		if(table.DataSet.Relations["Status*Customers.StatusID"] == null)
		{
			r = table.DataSet.Relations.Add("Status*Customers.StatusID", 
					table.DataSet.Tables["Status"].Columns["StatusID"],
					table.DataSet.Tables["Customers"].Columns["StatusID"]);
			r.ChildKeyConstraint.UpdateRule = Rule.None;
			r.ChildKeyConstraint.DeleteRule = Rule.None;
		}
 		if(table.DataSet.Relations["Customers*Orders.CustomerID"] == null)
		{
			r = table.DataSet.Relations.Add("Customers*Orders.CustomerID", 
					table.DataSet.Tables["Customers"].Columns["CustomerID"],
					table.DataSet.Tables["Orders"].Columns["CustomerID"]);
			r.ChildKeyConstraint.UpdateRule = Rule.None;
			r.ChildKeyConstraint.DeleteRule = Rule.None;
		}
	}
}

#endregion

#region CustomerSurrogateBase

/// <summary>Represents an entity object disconnected from the database.</summary>
/// <remarks>
///   <para>Database Path: CRMSample.Customers.</para>
/// </remarks>
[Serializable]
public abstract class CustomerSurrogateBase : EntityObjectSurrogate
{
    /// <summary>Default constructor.</summary>
    public CustomerSurrogateBase()
    {
    }
    
    /// <summary>
    /// Initializes a new instance of the <see cref="CustomerSurrogateBase"/> class.
    /// </summary>
    /// <param name="entity">The entity.</param>
    public CustomerSurrogateBase(Customer entity)
    {
		CustomerID = entity.CustomerID;
		Name = entity.Name;
		MailingAddressID = entity.MailingAddressID;
		DeliveryAddressID = entity.DeliveryAddressID;
		StatusID = entity.StatusID;
		Remarks = entity.Remarks;
    }
    
    /// <summary>
    /// Updates the entity with the values contained within the surrogate.
    /// </summary>
    /// <param name="entity">The entity.</param>
    public void BindObjectInstance(Customer entity)
    {
		if (entity.Row.RowState == DataRowState.Added)
        {
			entity.Name = Name;
			entity.MailingAddressID = MailingAddressID;
			entity.DeliveryAddressID = DeliveryAddressID;
			entity.StatusID = StatusID;
			entity.Remarks = Remarks;
		}
		else
		{
			if (_nameHasBeenUpdated)
			{
				entity.Name = Name;
			}
			if (_mailingaddressidHasBeenUpdated)
			{
				entity.MailingAddressID = MailingAddressID;
			}
			if (_deliveryaddressidHasBeenUpdated)
			{
				entity.DeliveryAddressID = DeliveryAddressID;
			}
			if (_statusidHasBeenUpdated)
			{
				entity.StatusID = StatusID;
			}
			if (_remarksHasBeenUpdated)
			{
				entity.Remarks = Remarks;
			}
		}
    }
    
    /// <summary>
    /// Property Orders </summary>
    /// <remarks> </remarks>
    /// <value> System.Collections.ArrayList </value>
    public System.Collections.ArrayList Orders
    {
    	get {return _orders;}
    	set {_orders = value;}
    }
		
	private System.Collections.ArrayList _orders;
	
	/// <summary>
    /// Property CustomerID - No Description </summary>
    /// <remarks> Database Path: CRMSample.Customers.CustomerID.</remarks>
    /// <value> System.Int32. </value>
    public System.Int32? CustomerID
    {
    	get {return _customerid;}
		set {_customerid = value;}
    }

	private System.Int32? _customerid;
	
    /// <summary>
    /// Property Name - No Description </summary>
    /// <remarks> Database Path: CRMSample.Customers.Name.</remarks>
    /// <value> System.String. </value>
    public System.String Name
    {
    	get {return _name;}
    	set {_name = value; _nameHasBeenUpdated = true;}
    }

	private System.String _name;
    private bool _nameHasBeenUpdated;
	
	/// <summary>
    /// Property MailingAddressID - No Description </summary>
    /// <remarks> Database Path: CRMSample.Customers.MailingAddressID.</remarks>
    /// <value> System.Guid. </value>
    public System.Guid? MailingAddressID
    {
    	get {return _mailingaddressid;}
    	set {_mailingaddressid = value; _mailingaddressidHasBeenUpdated = true;}
    }

	private System.Guid? _mailingaddressid;
    private bool _mailingaddressidHasBeenUpdated;
	
	/// <summary>
    /// Property DeliveryAddressID - No Description </summary>
    /// <remarks> Database Path: CRMSample.Customers.DeliveryAddressID.</remarks>
    /// <value> System.Guid. </value>
    public System.Guid? DeliveryAddressID
    {
    	get {return _deliveryaddressid;}
    	set {_deliveryaddressid = value; _deliveryaddressidHasBeenUpdated = true;}
    }

	private System.Guid? _deliveryaddressid;
    private bool _deliveryaddressidHasBeenUpdated;
	
	/// <summary>
    /// Property StatusID -  $attribute.Description </summary>
    /// <remarks> Database Path: CRMSample.Customers.StatusID.</remarks>
    /// <value> System.Int32. </value>
    public System.Int32? StatusID
    {
    	get {return _statusid;}
    	set {_statusid = value; _statusidHasBeenUpdated = true;}
    }

	private System.Int32? _statusid;
    private bool _statusidHasBeenUpdated;
	
    /// <summary>
    /// Property Remarks - No Description </summary>
    /// <remarks> Database Path: CRMSample.Customers.Remarks.</remarks>
    /// <value> System.String. </value>
    public System.String Remarks
    {
    	get {return _remarks;}
    	set {_remarks = value; _remarksHasBeenUpdated = true;}
    }

	private System.String _remarks;
    private bool _remarksHasBeenUpdated;
	
    /// <summary>
    /// Property MailingAddress - gets or sets the Address object with a one-to-one relationship to this instance.</summary>
    /// <remarks> Property MailingAddress - gets or sets the Address object with a one-to-one relationship to this instance.</remarks>
    /// <value> Address. </value>
    public AddressSurrogate MailingAddress
    {
    	get {return _mailingaddress;}
    	set {_mailingaddress = value;}
    }

	private AddressSurrogate _mailingaddress;
		
    /// <summary>
    /// Property DeliveryAddress - gets or sets the Address object with a one-to-one relationship to this instance.</summary>
    /// <remarks> Property DeliveryAddress - gets or sets the Address object with a one-to-one relationship to this instance.</remarks>
    /// <value> Address. </value>
    public AddressSurrogate DeliveryAddress
    {
    	get {return _deliveryaddress;}
    	set {_deliveryaddress = value;}
    }

	private AddressSurrogate _deliveryaddress;
		
    /// <summary>
    /// Property Status - gets or sets the Status object with a one-to-one relationship to this instance.</summary>
    /// <remarks> Property Status - gets or sets the Status object with a one-to-one relationship to this instance.</remarks>
    /// <value> Status. </value>
    public StatusSurrogate Status
    {
    	get {return _status;}
    	set {_status = value;}
    }

	private StatusSurrogate _status;
		

	/// <summary>
    /// Binds the surrogate values to the search template.
    /// </summary>
    /// <param name="emptyTemplate">The empty template.</param>
	public void BindToSearchTemplate(CustomerTemplate emptyTemplate)
    {
        if (this.MailingAddressID != null)
            emptyTemplate.MailingAddressID = this.MailingAddressID.Value;
        if (this.DeliveryAddressID != null)
            emptyTemplate.DeliveryAddressID = this.DeliveryAddressID.Value;
        if (this.StatusID != null)
            emptyTemplate.StatusID = this.StatusID.Value;
    }
    
	/// <summary>
	/// Determines whether this instance is valid.
	/// </summary>
	/// <returns>
	///	<c>true</c> if this instance is valid; otherwise, <c>false</c>.
	/// </returns>
    public abstract bool IsValid();

	/// <summary>
	/// Gets the validation message.
	/// </summary>
	/// <value>The validation message.</value>
    public abstract String ValidationMessage{get;}

}
#endregion

}

/* This is a customised template.
 * It overrides some optional methods from EntityMap to allow for testing 
 * with Mocks and fast object creation. Search for #custom# below. 
 */


namespace CRMSample.Models
{

#region Using statements

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using Neo.Core;
using Expergent;
using Expergent.Neo;
using Neo.Core.Util;
using Neo.Framework;

#endregion

#region AddressBase

/// <summary>
/// Generated table specific Base Class </summary>
/// <remarks> This class is generated by the Neo Framework. Make changes to NeoSupport.vtl.</remarks>
public partial class Address : RulesEnabledEntityObject
{
	/// <summary>
	/// A collection of Customer objects referencing this instance.</summary>
	/// <remarks> Objects referencing this instance.</remarks>
	public readonly ObjectRelation<Customer> CustomerMailingAddress;
	/// <summary>
	/// A collection of Customer objects referencing this instance.</summary>
	/// <remarks> Objects referencing this instance.</remarks>
	public readonly ObjectRelation<Customer> CustomerDeliveryAddress;
       
	internal Address(System.Data.DataRow aRow, Neo.Core.ObjectContext aContext) : base(aRow, aContext)
	{
		CustomerMailingAddress = new ObjectRelation<Customer>(this, "CustomerMailingAddress");
		CustomerDeliveryAddress = new ObjectRelation<Customer>(this, "CustomerDeliveryAddress");
	}
	
	/// <summary>
	/// Property AddressID -  $attribute.Description </summary>
	/// <remarks> Database Path: CRMSample.Addresses.AddressID.</remarks>
	/// <value> System.Guid. </value>
	public virtual System.Guid? AddressID
	{
		get { object v = Row["AddressID"]; return (System.Guid?)((v != DBNull.Value) ? v : null); }
		set { if (value.HasValue) Row["AddressID"] = value; else Row["AddressID"] = DBNull.Value; }
	}    

	/// <summary>
	/// Property Address1 -  $attribute.Description </summary>
	/// <remarks> Database Path: CRMSample.Addresses.Address1.</remarks>
	/// <value> System.String. </value>
	public virtual System.String Address1
	{
		get { return Row["Address1"] as System.String; }
		set { Row["Address1"] = (value != null) ? (object)value : (object)DBNull.Value; }
	}    

	/// <summary>
	/// Property Address2 -  $attribute.Description </summary>
	/// <remarks> Database Path: CRMSample.Addresses.Address2.</remarks>
	/// <value> System.String. </value>
	public virtual System.String Address2
	{
		get { return Row["Address2"] as System.String; }
		set { Row["Address2"] = (value != null) ? (object)value : (object)DBNull.Value; }
	}    

	/// <summary>
	/// Property City -  $attribute.Description </summary>
	/// <remarks> Database Path: CRMSample.Addresses.City.</remarks>
	/// <value> System.String. </value>
	public virtual System.String City
	{
		get { return Row["City"] as System.String; }
		set { Row["City"] = (value != null) ? (object)value : (object)DBNull.Value; }
	}    

	/// <summary>
	/// Property State -  $attribute.Description </summary>
	/// <remarks> Database Path: CRMSample.Addresses.State.</remarks>
	/// <value> System.String. </value>
	public virtual System.String State
	{
		get { return Row["State"] as System.String; }
		set { Row["State"] = (value != null) ? (object)value : (object)DBNull.Value; }
	}    

	/// <summary>
	/// Property Zip -  $attribute.Description </summary>
	/// <remarks> Database Path: CRMSample.Addresses.Zip.</remarks>
	/// <value> System.String. </value>
	public virtual System.String Zip
	{
		get { return Row["Zip"] as System.String; }
		set { Row["Zip"] = (value != null) ? (object)value : (object)DBNull.Value; }
	}    

	/// <summary>
	/// Property Zip4 -  $attribute.Description </summary>
	/// <remarks> Database Path: CRMSample.Addresses.Zip4.</remarks>
	/// <value> System.String. </value>
	public virtual System.String Zip4
	{
		get { return Row["Zip4"] as System.String; }
		set { Row["Zip4"] = (value != null) ? (object)value : (object)DBNull.Value; }
	}    


	/// <summary>
	/// Returns the value associated with the propName parameter.</summary>
	/// <remarks> You will need to cast the returned object into its native type upon return.</remarks>
	/// <param name="propName">String property name.</param>
	/// <returns> System.Object. </returns>
	public override object GetProperty(string propName)
	{
		if(propName == "AddressID") 
			return AddressID;
		if(propName == "Address1") 
			return Address1;
		if(propName == "Address2") 
			return Address2;
		if(propName == "City") 
			return City;
		if(propName == "State") 
			return State;
		if(propName == "Zip") 
			return Zip;
		if(propName == "Zip4") 
			return Zip4;
		if(propName == "CustomerMailingAddress") 
			return CustomerMailingAddress;
		if(propName == "CustomerDeliveryAddress") 
			return CustomerDeliveryAddress;
		return ExtendGetProperty(propName);
	}
	
	/// <summary>
    /// Sets the value associated with the propName parameter to the value specified.
    /// </summary>
    /// <param name="propName">String property name.</param>
    /// <param name="value">The value.</param>
	public override void SetProperty(string propName, object value)
	{
		if(propName == "AddressID") 
		{
			AddressID = (System.Guid?)value;
			return;
		}
		if(propName == "Address1") 
		{
			Address1 = (System.String)value;
			return;
		}
		if(propName == "Address2") 
		{
			Address2 = (System.String)value;
			return;
		}
		if(propName == "City") 
		{
			City = (System.String)value;
			return;
		}
		if(propName == "State") 
		{
			State = (System.String)value;
			return;
		}
		if(propName == "Zip") 
		{
			Zip = (System.String)value;
			return;
		}
		if(propName == "Zip4") 
		{
			Zip4 = (System.String)value;
			return;
		}
		ExtendSetProperty(propName, value);
	}

    /// <summary>
    /// Ensures related tables are loaded into memory for a cascaded delete.</summary>
    /// <remarks> Deletes related tables entries when cascade is specified.</remarks>
    public override void Delete() 
    {
        CustomerMailingAddress.Touch();
        while (CustomerMailingAddress.Count > 0)
        {
            CustomerMailingAddress[0].Delete();
        }
        CustomerDeliveryAddress.Touch();
        while (CustomerDeliveryAddress.Count > 0)
        {
            CustomerDeliveryAddress[0].Delete();
        }
        base.Delete();
    }

    /// <summary>
    /// Adds a set of facts for this instance to the list.
    /// </summary>
    /// <param name="list">The list.</param>
    /// <param name="parent">The parent.</param>
    protected override void MakeFacts(List<WME> list, string parent)
    {
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "AddressID"), AddressID));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "Address1"), Address1));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "Address2"), Address2));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "City"), City));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "State"), State));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "Zip"), Zip));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "Zip4"), Zip4));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "CustomerMailingAddress"), CustomerMailingAddress));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "CustomerDeliveryAddress"), CustomerDeliveryAddress));
        ExtendMakeFacts(list, parent);
        myFactsHaveBeenAsserted = true;
    }

	/// <summary>
    /// Populates the EntityObject from the specified surrogate.
    /// </summary>
    /// <param name="surrogate">The surrogate.</param>
	public void Populate(AddressSurrogate surrogate)
	{
		Address1 = surrogate.Address1;
		Address2 = surrogate.Address2;
		City = surrogate.City;
		State = surrogate.State;
		Zip = surrogate.Zip;
		Zip4 = surrogate.Zip4;
	}
}

#endregion

#region AddressTemplate

/// <summary>
/// Generated table specific Query Template Class </summary>
/// <remarks> A Query Template for Address operations. </remarks>
public class AddressTemplate : QueryTemplate
{

	/// <summary>
	/// Constructor </summary>
	/// <remarks> Public Constructor.</remarks>
	/// <param name="anEntityMap">IEntityMap instance.</param>
	public AddressTemplate(IEntityMap anEntityMap) : base(anEntityMap)
	{
	}
	
	/// <summary>
	/// Property AddressID -  $attributes.Description </summary>
	/// <remarks> Database Path: CRMSample.Addresses.AddressID.</remarks>
	/// <value> System.Guid. </value>
	public System.Guid AddressID
	{
		get { return (System.Guid)QueryValues["AddressID"]; }
		set { QueryValues["AddressID"] = value; }
	}

	/// <summary>
	/// Property Address1 -  $attributes.Description </summary>
	/// <remarks> Database Path: CRMSample.Addresses.Address1.</remarks>
	/// <value> System.String. </value>
	public System.String Address1
	{
		get { return (System.String)QueryValues["Address1"]; }
		set { QueryValues["Address1"] = value; }
	}

	/// <summary>
	/// Property Address2 -  $attributes.Description </summary>
	/// <remarks> Database Path: CRMSample.Addresses.Address2.</remarks>
	/// <value> System.String. </value>
	public System.String Address2
	{
		get { return (System.String)QueryValues["Address2"]; }
		set { QueryValues["Address2"] = value; }
	}

	/// <summary>
	/// Property City -  $attributes.Description </summary>
	/// <remarks> Database Path: CRMSample.Addresses.City.</remarks>
	/// <value> System.String. </value>
	public System.String City
	{
		get { return (System.String)QueryValues["City"]; }
		set { QueryValues["City"] = value; }
	}

	/// <summary>
	/// Property State -  $attributes.Description </summary>
	/// <remarks> Database Path: CRMSample.Addresses.State.</remarks>
	/// <value> System.String. </value>
	public System.String State
	{
		get { return (System.String)QueryValues["State"]; }
		set { QueryValues["State"] = value; }
	}

	/// <summary>
	/// Property Zip -  $attributes.Description </summary>
	/// <remarks> Database Path: CRMSample.Addresses.Zip.</remarks>
	/// <value> System.String. </value>
	public System.String Zip
	{
		get { return (System.String)QueryValues["Zip"]; }
		set { QueryValues["Zip"] = value; }
	}

	/// <summary>
	/// Property Zip4 -  $attributes.Description </summary>
	/// <remarks> Database Path: CRMSample.Addresses.Zip4.</remarks>
	/// <value> System.String. </value>
	public System.String Zip4
	{
		get { return (System.String)QueryValues["Zip4"]; }
		set { QueryValues["Zip4"] = value; }
	}

               
}

#endregion

#region AddressFactory

/// <summary>
/// Factory class for the creation of Address objects.</summary>
/// <remarks> This class is generated by the Neo Framework. Make changes to NeoSupport.vtl.</remarks>
public class AddressFactory : Neo.Framework.ObjectFactory
{

	/// <summary>
	/// Constructor requiring an ObjectContext parameter.</summary>
	/// <remarks> Main entry point for the retrieval and creation of new Address objects.</remarks>
	/// <param name="context">ObjectContext.</param>
	public AddressFactory(ObjectContext context) : base(context, typeof(Address))
	{
	}

	/// <summary>
	/// Create new Address object.</summary>
	/// <remarks>IdMethod = Guid, PrimaryKeyIsForeignKey = False, RelationshipSetsForColumns = 2.</remarks>
	/// <returns> Address </returns>
	public Address CreateObject()
	{
		return (Address)base.CreateObject(null);
	}
	

	/// <summary>
	/// Find a specified Address object.</summary>
	/// <remarks> Requires Primary Key values and/or parent object instances.</remarks>
	/// <param name="arg0">$column.Description.</param>
	/// <returns> Address </returns>
	public Address FindObject(System.Guid arg0)
	{
		return (Address)base.FindObject(new object[] { arg0 } );
	}

	///<summary>
	///Find a specified Address object.</summary>
	///<remarks> Requires Primary Key values and/or parent object instances.</remarks>
	///<param name="arg0">$column.Description.</param>
	///<returns> Address </returns>
	public Address FindObjectByPK( System.Guid arg0 )
	{
		return (Address) base.FindObject( new object[] {  arg0 } );
	}
	

	///<summary>
	///Find a specified Address object.</summary>
	///<remarks> Requires Primary Key values and/or parent object instances.</remarks>
	///<param name="arg0">$column.Description.</param>
	///<returns> Address </returns>
	public Address FindObjectByPK( System.Guid? arg0 )
	{
		return (Address) base.FindObject( new object[] {  arg0.Value } );
	}

	/// <summary>
	/// Find a list of Address objects.</summary>
	/// <remarks> Returns all.</remarks>
	/// <returns> ObjectList&lt;Address&gt; </returns>
	public new ObjectList<Address> FindAllObjects()
	{
		ObjectList<Address> c = new ObjectList<Address>();
		foreach(Address eo in base.FindAllObjects())
			c.Add(eo);
		return c;
	}
	
	/// <summary>
	/// Return the correct Query Template for the Address object.</summary>
	/// <remarks> A query template is used for creating SQL like queries, in a more OO fashion.</remarks>
	/// <returns> AddressTemplate </returns>
	public AddressTemplate GetQueryTemplate()
	{
		return new AddressTemplate(EntityMap);
	}
	
	/// <summary>
	/// SQL like query to find and return a list of objects based on a template.</summary>
	/// <remarks> A query template is used for creating SQL like queries, in a more OO fashion.</remarks>
	/// <param name="template">AddressTemplate.</param>
	/// <returns> ObjectList&lt;Address&gt; </returns>
	public ObjectList<Address> Find(AddressTemplate template)
	{
		ObjectList<Address> c = new ObjectList<Address>();
		foreach(Address eo in base.Find(template))
			c.Add(eo);
		return c;
	}

	/// <summary>
	/// SQL like query to find and return a list of objects based on a FetchSpecification.</summary>
	/// <remarks> A query Fetch Specification is used for creating SQL like queries, in a more OO fashion.</remarks>
	/// <param name="fetchSpecification">FetchSpecification.</param>
	/// <returns> ObjectList&lt;Address&gt; </returns>
	public ObjectList<Address> Find(FetchSpecification fetchSpecification)
	{
		ObjectList<Address> c = new ObjectList<Address>();
		foreach(Address eo in base.Find(fetchSpecification))
			c.Add(eo);
		return c;
	}
	
	/// <summary>
	/// SQL like query to find and return a list of objects.</summary>
	/// <remarks> For example: ...Find("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> ObjectList&lt;Address&gt; </returns>
	public new ObjectList<Address> Find(string qualifierFormat, params object[] parameters)
	{
		ObjectList<Address> c = new ObjectList<Address>();
		foreach(Address eo in base.Find(qualifierFormat, parameters))
			c.Add(eo);
		return c;
	}

	/// <summary>
	/// SQL like query to find and return a list of objects limiting the munber of items returned.</summary>
	/// <remarks> For example: ...Find(10, "TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="limit">Int32.</param>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> ObjectList&lt;Address&gt; </returns>
	public new ObjectList<Address> FindWithLimit(int limit, string qualifierFormat, params object[] parameters)
	{
		ObjectList<Address> c = new ObjectList<Address>();
		foreach(Address eo in base.Find(qualifierFormat, parameters))
			c.Add(eo);
		return c;
	}
	
	/// <summary>
	/// SQL like query to find and return an object.</summary>
	/// <remarks> For example: ...FindFirst("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> Address. </returns>
	public new Address FindFirst(string qualifierFormat, params object[] parameters)
	{
		return (Address)base.FindFirst(qualifierFormat, parameters);
	}

	/// <summary>
	/// SQL like query to find and return an object.</summary>
	/// <remarks> For example: ...FindUnique("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> Address. </returns>
	public new Address FindUnique(string qualifierFormat, params object[] parameters)
	{
		return (Address)base.FindUnique(qualifierFormat, parameters);
	}	

	
}

#endregion

#region AddressEntityMap

//  -------- Entity Map -----------------------------------------------------
/// <summary>Creates the in memory version of the dataset for the Address DOM.</summary>
/// <remarks>Generated by Neo Framework.</remarks>
internal class AddressMap : EntityMap
{
	  /// <summary>Array of Primary Key column names.</summary>
	  /// <remarks>Primary Key columns.</remarks>
    private static readonly string[] pkcolumns = { "AddressID" };
    /// <summary>Array of Database column names.</summary>
	  /// <remarks>Database column names.</remarks>
    private static readonly string[] columns = { "AddressID", "Address1", "Address2", "City", "State", "Zip", "Zip4" };
    /// <summary>Array of DOM object properties.</summary>
	  /// <remarks>DOM object properties.</remarks>
    private static readonly string[] attributes = { "AddressID", "Address1", "Address2", "City", "State", "Zip", "Zip4" };
    /// <summary>Array of Related Object names.</summary>
	  /// <remarks>Related Object names.</remarks>
    private static readonly string[] relations = { "CustomerMailingAddress", "CustomerDeliveryAddress" };

    private Type concreteObjectType = typeof(Address);

	  /// <summary>Property ObjectType.</summary>
	  /// <remarks>Returns the DOM's Type.</remarks>
	  /// <value>System.Type.</value>
    public override System.Type ObjectType
    {
        get { return typeof(Address); }
    }
    
    /// <summary>Property ObjectType.</summary>
	  /// <remarks>Returns the DOM's Type.</remarks>
	  /// <value>System.Type.</value>
    public override System.Type ConcreteObjectType
    {
        get { return concreteObjectType; }										 /* #custom# overridden */
        set { concreteObjectType = value; Factory.AddCustomType(value, this); }  /* #custom# overridden */
    }
    
    /// <summary>Property TableName.</summary>
	  /// <remarks>Returns database table name.</remarks>
	  /// <value>string.</value>
    public override string TableName
    {
        get { return "Addresses"; }
    }
    
    /// <summary>Property PrimaryKeyColumns.</summary>
	/// <remarks>Array of Primary Key column names.</remarks>
	/// <value>string[].</value>
    public override string[] PrimaryKeyColumns
    {
        get { return pkcolumns; }
    }

	/// <summary>Property Columns.</summary>
	/// <remarks>Array of Database column names.</remarks>
	/// <value>string[].</value>
    public override string[] Columns
    {
        get { return columns; }
    }

	/// <summary>Property Attributes.</summary>
	/// <remarks>Array of DOM object properties.</remarks>
	/// <value>string[].</value>
    public override string[] Attributes
    {
        get { return attributes; }
    }

    /// <summary>Property Relations.</summary>
	/// <remarks>Array of Related Object names.</remarks>
	/// <value>string[].</value>
    public override string[] Relations
    {
        get { return relations; }
    }

	/// <summary>Generates a Hashtable, keyed by Object Name, or information regarding related objects.</summary>
	/// <remarks>Related Objects.</remarks>
	/// <returns>IDictionary.</returns>
  	protected override IDictionary GetRelationInfos()
    {
    	IDictionary infos = new Hashtable(2);
  		infos.Add("CustomerMailingAddress", new RelationInfo(Factory, typeof(Address), typeof(Customer), "AddressID", "MailingAddressID"));
 		infos.Add("CustomerDeliveryAddress", new RelationInfo(Factory, typeof(Address), typeof(Customer), "AddressID", "DeliveryAddressID"));
		return infos;    	
    }
    
	/// <summary>Based upon the model specified Id Method, returns the proper PkInitializer.</summary>
	/// <remarks>The object used to create a new PK value.</remarks>
	/// <returns>IPkInitializer.</returns>
	public override IPkInitializer GetPkInitializer()
	{
		return new GuidPkInitializer();
	}
    
	/// <summary>Creates a new instance of Address.</summary>
	/// <remarks>Create new Address.</remarks>
	/// <param name="row">DataRow.</param>
	/// <param name="context">ObjectContext.</param>
	/// <returns>IEntityObject.</returns>
    public override IEntityObject CreateInstance(DataRow row, ObjectContext context) /* #custom# overridden */
    {
		if(ConcreteObjectType != ObjectType)
			return base.CreateInstance(row, context);
		return new Address(row, context);
	}
    
    /// <summary>Generates the in memory dataset.</summary>
	/// <remarks>Called by the Factory object.</remarks>
	/// <param name="table">DataTable.</param>
    protected override void WriteBasicSchema(DataTable table)
    {
		DataColumn		c;
		
		c = table.Columns.Add("AddressID", typeof(System.Guid));
		c.Unique = true;
		c = table.Columns.Add("Address1", typeof(System.String));
		c = table.Columns.Add("Address2", typeof(System.String));
		c.AllowDBNull = true;
		c = table.Columns.Add("City", typeof(System.String));
		c = table.Columns.Add("State", typeof(System.String));
		c = table.Columns.Add("Zip", typeof(System.String));
		c = table.Columns.Add("Zip4", typeof(System.String));
		table.PrimaryKey = new DataColumn[] { table.Columns["AddressID"] };
	}
	
	/// <summary>Generates the dataset relationships.</summary>
	/// <remarks>Dataset Relationships.</remarks>
	/// <param name="table">DataTable.</param>
	protected override void WriteRelations(DataTable table)
	{
		DataRelation r;
		
 		if(table.DataSet.Relations["Addresses*Customers.MailingAddressID"] == null)
		{
			r = table.DataSet.Relations.Add("Addresses*Customers.MailingAddressID", 
					table.DataSet.Tables["Addresses"].Columns["AddressID"],
					table.DataSet.Tables["Customers"].Columns["MailingAddressID"]);
			r.ChildKeyConstraint.UpdateRule = Rule.None;
			r.ChildKeyConstraint.DeleteRule = Rule.None;
		}
 		if(table.DataSet.Relations["Addresses*Customers.DeliveryAddressID"] == null)
		{
			r = table.DataSet.Relations.Add("Addresses*Customers.DeliveryAddressID", 
					table.DataSet.Tables["Addresses"].Columns["AddressID"],
					table.DataSet.Tables["Customers"].Columns["DeliveryAddressID"]);
			r.ChildKeyConstraint.UpdateRule = Rule.None;
			r.ChildKeyConstraint.DeleteRule = Rule.None;
		}
	}
}

#endregion

#region AddressSurrogateBase

/// <summary>Represents an entity object disconnected from the database.</summary>
/// <remarks>
///   <para>Database Path: CRMSample.Addresses.</para>
/// </remarks>
[Serializable]
public abstract class AddressSurrogateBase : EntityObjectSurrogate
{
    /// <summary>Default constructor.</summary>
    public AddressSurrogateBase()
    {
    }
    
    /// <summary>
    /// Initializes a new instance of the <see cref="AddressSurrogateBase"/> class.
    /// </summary>
    /// <param name="entity">The entity.</param>
    public AddressSurrogateBase(Address entity)
    {
		AddressID = entity.AddressID;
		Address1 = entity.Address1;
		Address2 = entity.Address2;
		City = entity.City;
		State = entity.State;
		Zip = entity.Zip;
		Zip4 = entity.Zip4;
    }
    
    /// <summary>
    /// Updates the entity with the values contained within the surrogate.
    /// </summary>
    /// <param name="entity">The entity.</param>
    public void BindObjectInstance(Address entity)
    {
		if (entity.Row.RowState == DataRowState.Added)
        {
			entity.Address1 = Address1;
			entity.Address2 = Address2;
			entity.City = City;
			entity.State = State;
			entity.Zip = Zip;
			entity.Zip4 = Zip4;
		}
		else
		{
			if (_address1HasBeenUpdated)
			{
				entity.Address1 = Address1;
			}
			if (_address2HasBeenUpdated)
			{
				entity.Address2 = Address2;
			}
			if (_cityHasBeenUpdated)
			{
				entity.City = City;
			}
			if (_stateHasBeenUpdated)
			{
				entity.State = State;
			}
			if (_zipHasBeenUpdated)
			{
				entity.Zip = Zip;
			}
			if (_zip4HasBeenUpdated)
			{
				entity.Zip4 = Zip4;
			}
		}
    }
    
    /// <summary>
    /// Property CustomerMailingAddress </summary>
    /// <remarks> </remarks>
    /// <value> System.Collections.ArrayList </value>
    public System.Collections.ArrayList CustomerMailingAddress
    {
    	get {return _customermailingaddress;}
    	set {_customermailingaddress = value;}
    }
		
	private System.Collections.ArrayList _customermailingaddress;
	
    /// <summary>
    /// Property CustomerDeliveryAddress </summary>
    /// <remarks> </remarks>
    /// <value> System.Collections.ArrayList </value>
    public System.Collections.ArrayList CustomerDeliveryAddress
    {
    	get {return _customerdeliveryaddress;}
    	set {_customerdeliveryaddress = value;}
    }
		
	private System.Collections.ArrayList _customerdeliveryaddress;
	
	/// <summary>
    /// Property AddressID -  $attribute.Description </summary>
    /// <remarks> Database Path: CRMSample.Addresses.AddressID.</remarks>
    /// <value> System.Guid. </value>
    public System.Guid? AddressID
    {
    	get {return _addressid;}
		set {_addressid = value;}
    }

	private System.Guid? _addressid;
	
    /// <summary>
    /// Property Address1 -  $attribute.Description </summary>
    /// <remarks> Database Path: CRMSample.Addresses.Address1.</remarks>
    /// <value> System.String. </value>
    public System.String Address1
    {
    	get {return _address1;}
    	set {_address1 = value; _address1HasBeenUpdated = true;}
    }

	private System.String _address1;
    private bool _address1HasBeenUpdated;
	
    /// <summary>
    /// Property Address2 -  $attribute.Description </summary>
    /// <remarks> Database Path: CRMSample.Addresses.Address2.</remarks>
    /// <value> System.String. </value>
    public System.String Address2
    {
    	get {return _address2;}
    	set {_address2 = value; _address2HasBeenUpdated = true;}
    }

	private System.String _address2;
    private bool _address2HasBeenUpdated;
	
    /// <summary>
    /// Property City -  $attribute.Description </summary>
    /// <remarks> Database Path: CRMSample.Addresses.City.</remarks>
    /// <value> System.String. </value>
    public System.String City
    {
    	get {return _city;}
    	set {_city = value; _cityHasBeenUpdated = true;}
    }

	private System.String _city;
    private bool _cityHasBeenUpdated;
	
    /// <summary>
    /// Property State -  $attribute.Description </summary>
    /// <remarks> Database Path: CRMSample.Addresses.State.</remarks>
    /// <value> System.String. </value>
    public System.String State
    {
    	get {return _state;}
    	set {_state = value; _stateHasBeenUpdated = true;}
    }

	private System.String _state;
    private bool _stateHasBeenUpdated;
	
    /// <summary>
    /// Property Zip -  $attribute.Description </summary>
    /// <remarks> Database Path: CRMSample.Addresses.Zip.</remarks>
    /// <value> System.String. </value>
    public System.String Zip
    {
    	get {return _zip;}
    	set {_zip = value; _zipHasBeenUpdated = true;}
    }

	private System.String _zip;
    private bool _zipHasBeenUpdated;
	
    /// <summary>
    /// Property Zip4 -  $attribute.Description </summary>
    /// <remarks> Database Path: CRMSample.Addresses.Zip4.</remarks>
    /// <value> System.String. </value>
    public System.String Zip4
    {
    	get {return _zip4;}
    	set {_zip4 = value; _zip4HasBeenUpdated = true;}
    }

	private System.String _zip4;
    private bool _zip4HasBeenUpdated;
	

	/// <summary>
    /// Binds the surrogate values to the search template.
    /// </summary>
    /// <param name="emptyTemplate">The empty template.</param>
	public void BindToSearchTemplate(AddressTemplate emptyTemplate)
    {
    }
    
	/// <summary>
	/// Determines whether this instance is valid.
	/// </summary>
	/// <returns>
	///	<c>true</c> if this instance is valid; otherwise, <c>false</c>.
	/// </returns>
    public abstract bool IsValid();

	/// <summary>
	/// Gets the validation message.
	/// </summary>
	/// <value>The validation message.</value>
    public abstract String ValidationMessage{get;}

}
#endregion

}

/* This is a customised template.
 * It overrides some optional methods from EntityMap to allow for testing 
 * with Mocks and fast object creation. Search for #custom# below. 
 */


namespace CRMSample.Models
{

#region Using statements

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using Neo.Core;
using Expergent;
using Expergent.Neo;
using Neo.Core.Util;
using Neo.Framework;

#endregion

#region OrderBase

/// <summary>
/// Generated table specific Base Class </summary>
/// <remarks> This class is generated by the Neo Framework. Make changes to NeoSupport.vtl.</remarks>
public partial class Order : RulesEnabledEntityObject
{
	/// <summary>
	/// A collection of OrderItem objects referencing this instance.</summary>
	/// <remarks> Objects referencing this instance.</remarks>
	public readonly ObjectRelation<OrderItem> OrderItems;
       
	internal Order(System.Data.DataRow aRow, Neo.Core.ObjectContext aContext) : base(aRow, aContext)
	{
		OrderItems = new ObjectRelation<OrderItem>(this, "OrderItems");
	}
	
	/// <summary>
	/// Property OrderID -  $attribute.Description </summary>
	/// <remarks> Database Path: CRMSample.Orders.OrderID.</remarks>
	/// <value> System.Int32. </value>
	public virtual System.Int32? OrderID
	{
		get { object v = Row["OrderID"]; return (System.Int32?)((v != DBNull.Value) ? v : null); }
		set { if (value.HasValue) Row["OrderID"] = value; else Row["OrderID"] = DBNull.Value; }
	}    

	/// <summary>
	/// Property CustomerID - No Description </summary>
	/// <remarks> Database Path: CRMSample.Orders.CustomerID.</remarks>
	/// <value> System.Int32. </value>
	public virtual System.Int32? CustomerID
	{
		get { object v = Row["CustomerID"]; return (System.Int32?)((v != DBNull.Value) ? v : null); }
		set { if (value.HasValue) Row["CustomerID"] = value; else Row["CustomerID"] = DBNull.Value; }
	}    

	/// <summary>
	/// Property OrderDate -  $attribute.Description </summary>
	/// <remarks> Database Path: CRMSample.Orders.OrderDate.</remarks>
	/// <value> System.DateTime. </value>
	public virtual System.DateTime? OrderDate
	{
		get { object v = Row["OrderDate"]; return (System.DateTime?)((v != DBNull.Value) ? v : null); }
		set { if (value.HasValue) Row["OrderDate"] = value; else Row["OrderDate"] = DBNull.Value; }
	}    

	/// <summary>
	/// Property OrderAmount -  $attribute.Description </summary>
	/// <remarks> Database Path: CRMSample.Orders.OrderAmount.</remarks>
	/// <value> System.Decimal. </value>
	public virtual System.Decimal? OrderAmount
	{
		get { object v = Row["OrderAmount"]; return (System.Decimal?)((v != DBNull.Value) ? v : null); }
		set { if (value.HasValue) Row["OrderAmount"] = value; else Row["OrderAmount"] = DBNull.Value; }
	}    


	/// <summary>
	/// Property Customer - gets or sets the Customer object with a one-to-one relationship to this instance.</summary>
	/// <remarks> Property Customer - gets or sets the Customer object with a one-to-one relationship to this instance.</remarks>
	/// <value> Customer. </value>
	public virtual Customer Customer
	{
		get { object fk = Row["CustomerID"]; return (fk == DBNull.Value) ? null : (Customer)GetRelatedObject("Customers", fk); }
		set { SetRelatedObject(value, "CustomerID", "CustomerID" ); }
	}

	/// <summary>
	/// Returns the value associated with the propName parameter.</summary>
	/// <remarks> You will need to cast the returned object into its native type upon return.</remarks>
	/// <param name="propName">String property name.</param>
	/// <returns> System.Object. </returns>
	public override object GetProperty(string propName)
	{
		if(propName == "OrderID") 
			return OrderID;
		if(propName == "CustomerID") 
			return CustomerID;
		if(propName == "OrderDate") 
			return OrderDate;
		if(propName == "OrderAmount") 
			return OrderAmount;
		if(propName == "Customer") 
			return Customer;
		if(propName == "OrderItems") 
			return OrderItems;
		return ExtendGetProperty(propName);
	}
	
	/// <summary>
    /// Sets the value associated with the propName parameter to the value specified.
    /// </summary>
    /// <param name="propName">String property name.</param>
    /// <param name="value">The value.</param>
	public override void SetProperty(string propName, object value)
	{
		if(propName == "OrderID") 
		{
			OrderID = (System.Int32?)value;
			return;
		}
		if(propName == "CustomerID") 
		{
			CustomerID = (System.Int32?)value;
			return;
		}
		if(propName == "OrderDate") 
		{
			OrderDate = (System.DateTime?)value;
			return;
		}
		if(propName == "OrderAmount") 
		{
			OrderAmount = (System.Decimal?)value;
			return;
		}
		if(propName == "Customer") 
		{
			Customer = (Customer)value;
			return;
		}
		ExtendSetProperty(propName, value);
	}

    /// <summary>
    /// Ensures related tables are loaded into memory for a cascaded delete.</summary>
    /// <remarks> Deletes related tables entries when cascade is specified.</remarks>
    public override void Delete() 
    {
        OrderItems.Touch();
        while (OrderItems.Count > 0)
        {
            OrderItems[0].Delete();
        }
        base.Delete();
    }

    /// <summary>
    /// Adds a set of facts for this instance to the list.
    /// </summary>
    /// <param name="list">The list.</param>
    /// <param name="parent">The parent.</param>
    protected override void MakeFacts(List<WME> list, string parent)
    {
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "OrderID"), OrderID));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "CustomerID"), CustomerID));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "OrderDate"), OrderDate));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "OrderAmount"), OrderAmount));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "Customer"), Customer));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "OrderItems"), OrderItems));
        ExtendMakeFacts(list, parent);
        myFactsHaveBeenAsserted = true;
    }

	/// <summary>
    /// Populates the EntityObject from the specified surrogate.
    /// </summary>
    /// <param name="surrogate">The surrogate.</param>
	public void Populate(OrderSurrogate surrogate)
	{
		CustomerID = surrogate.CustomerID;
		OrderDate = surrogate.OrderDate;
		OrderAmount = surrogate.OrderAmount;
	}
}

#endregion

#region OrderTemplate

/// <summary>
/// Generated table specific Query Template Class </summary>
/// <remarks> A Query Template for Order operations. </remarks>
public class OrderTemplate : QueryTemplate
{

	/// <summary>
	/// Constructor </summary>
	/// <remarks> Public Constructor.</remarks>
	/// <param name="anEntityMap">IEntityMap instance.</param>
	public OrderTemplate(IEntityMap anEntityMap) : base(anEntityMap)
	{
	}
	
	/// <summary>
	/// Property OrderID -  $attributes.Description </summary>
	/// <remarks> Database Path: CRMSample.Orders.OrderID.</remarks>
	/// <value> System.Int32. </value>
	public System.Int32 OrderID
	{
		get { return (System.Int32)QueryValues["OrderID"]; }
		set { QueryValues["OrderID"] = value; }
	}

	/// <summary>
	/// Property CustomerID - No Description </summary>
	/// <remarks> Database Path: CRMSample.Orders.CustomerID.</remarks>
	/// <value> System.Int32. </value>
	public System.Int32 CustomerID
	{
		get { return (System.Int32)QueryValues["CustomerID"]; }
		set { QueryValues["CustomerID"] = value; }
	}

	/// <summary>
	/// Property OrderDate -  $attributes.Description </summary>
	/// <remarks> Database Path: CRMSample.Orders.OrderDate.</remarks>
	/// <value> System.DateTime. </value>
	public System.DateTime OrderDate
	{
		get { return (System.DateTime)QueryValues["OrderDate"]; }
		set { QueryValues["OrderDate"] = value; }
	}

	/// <summary>
	/// Property OrderAmount -  $attributes.Description </summary>
	/// <remarks> Database Path: CRMSample.Orders.OrderAmount.</remarks>
	/// <value> System.Decimal. </value>
	public System.Decimal OrderAmount
	{
		get { return (System.Decimal)QueryValues["OrderAmount"]; }
		set { QueryValues["OrderAmount"] = value; }
	}

	/// <summary>
	/// Property Customer - gets or sets the Customer object with a one-to-one relationship to this instance.</summary>
	/// <remarks> Gets or sets the Customer object.</remarks>
	/// <value> Customer. </value>
	public Customer Customer
	{
		get { return (Customer)QueryValues["Customer"]; }
		set { QueryValues["Customer"] = value; }
	}

               
}

#endregion

#region OrderFactory

/// <summary>
/// Factory class for the creation of Order objects.</summary>
/// <remarks> This class is generated by the Neo Framework. Make changes to NeoSupport.vtl.</remarks>
public class OrderFactory : Neo.Framework.ObjectFactory
{

	/// <summary>
	/// Constructor requiring an ObjectContext parameter.</summary>
	/// <remarks> Main entry point for the retrieval and creation of new Order objects.</remarks>
	/// <param name="context">ObjectContext.</param>
	public OrderFactory(ObjectContext context) : base(context, typeof(Order))
	{
	}

	/// <summary>
	/// Create new Order object.</summary>
	/// <remarks>IdMethod = Native, PrimaryKeyIsForeignKey = False, RelationshipSetsForColumns = 1.</remarks>
	/// <returns> Order </returns>
	public Order CreateObject()
	{
		return (Order)base.CreateObject(null);
	}
	

	/// <summary>
	/// Find a specified Order object.</summary>
	/// <remarks> Requires Primary Key values and/or parent object instances.</remarks>
	/// <param name="arg0">$column.Description.</param>
	/// <returns> Order </returns>
	public Order FindObject(System.Int32 arg0)
	{
		return (Order)base.FindObject(new object[] { arg0 } );
	}

	///<summary>
	///Find a specified Order object.</summary>
	///<remarks> Requires Primary Key values and/or parent object instances.</remarks>
	///<param name="arg0">$column.Description.</param>
	///<returns> Order </returns>
	public Order FindObjectByPK( System.Int32 arg0 )
	{
		return (Order) base.FindObject( new object[] {  arg0 } );
	}
	

	///<summary>
	///Find a specified Order object.</summary>
	///<remarks> Requires Primary Key values and/or parent object instances.</remarks>
	///<param name="arg0">$column.Description.</param>
	///<returns> Order </returns>
	public Order FindObjectByPK( System.Int32? arg0 )
	{
		return (Order) base.FindObject( new object[] {  arg0.Value } );
	}

	/// <summary>
	/// Find a list of Order objects.</summary>
	/// <remarks> Returns all.</remarks>
	/// <returns> ObjectList&lt;Order&gt; </returns>
	public new ObjectList<Order> FindAllObjects()
	{
		ObjectList<Order> c = new ObjectList<Order>();
		foreach(Order eo in base.FindAllObjects())
			c.Add(eo);
		return c;
	}
	
	/// <summary>
	/// Return the correct Query Template for the Order object.</summary>
	/// <remarks> A query template is used for creating SQL like queries, in a more OO fashion.</remarks>
	/// <returns> OrderTemplate </returns>
	public OrderTemplate GetQueryTemplate()
	{
		return new OrderTemplate(EntityMap);
	}
	
	/// <summary>
	/// SQL like query to find and return a list of objects based on a template.</summary>
	/// <remarks> A query template is used for creating SQL like queries, in a more OO fashion.</remarks>
	/// <param name="template">OrderTemplate.</param>
	/// <returns> ObjectList&lt;Order&gt; </returns>
	public ObjectList<Order> Find(OrderTemplate template)
	{
		ObjectList<Order> c = new ObjectList<Order>();
		foreach(Order eo in base.Find(template))
			c.Add(eo);
		return c;
	}

	/// <summary>
	/// SQL like query to find and return a list of objects based on a FetchSpecification.</summary>
	/// <remarks> A query Fetch Specification is used for creating SQL like queries, in a more OO fashion.</remarks>
	/// <param name="fetchSpecification">FetchSpecification.</param>
	/// <returns> ObjectList&lt;Order&gt; </returns>
	public ObjectList<Order> Find(FetchSpecification fetchSpecification)
	{
		ObjectList<Order> c = new ObjectList<Order>();
		foreach(Order eo in base.Find(fetchSpecification))
			c.Add(eo);
		return c;
	}
	
	/// <summary>
	/// SQL like query to find and return a list of objects.</summary>
	/// <remarks> For example: ...Find("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> ObjectList&lt;Order&gt; </returns>
	public new ObjectList<Order> Find(string qualifierFormat, params object[] parameters)
	{
		ObjectList<Order> c = new ObjectList<Order>();
		foreach(Order eo in base.Find(qualifierFormat, parameters))
			c.Add(eo);
		return c;
	}

	/// <summary>
	/// SQL like query to find and return a list of objects limiting the munber of items returned.</summary>
	/// <remarks> For example: ...Find(10, "TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="limit">Int32.</param>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> ObjectList&lt;Order&gt; </returns>
	public new ObjectList<Order> FindWithLimit(int limit, string qualifierFormat, params object[] parameters)
	{
		ObjectList<Order> c = new ObjectList<Order>();
		foreach(Order eo in base.Find(qualifierFormat, parameters))
			c.Add(eo);
		return c;
	}
	
	/// <summary>
	/// SQL like query to find and return an object.</summary>
	/// <remarks> For example: ...FindFirst("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> Order. </returns>
	public new Order FindFirst(string qualifierFormat, params object[] parameters)
	{
		return (Order)base.FindFirst(qualifierFormat, parameters);
	}

	/// <summary>
	/// SQL like query to find and return an object.</summary>
	/// <remarks> For example: ...FindUnique("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> Order. </returns>
	public new Order FindUnique(string qualifierFormat, params object[] parameters)
	{
		return (Order)base.FindUnique(qualifierFormat, parameters);
	}	

	
}

#endregion

#region OrderEntityMap

//  -------- Entity Map -----------------------------------------------------
/// <summary>Creates the in memory version of the dataset for the Order DOM.</summary>
/// <remarks>Generated by Neo Framework.</remarks>
internal class OrderMap : EntityMap
{
	  /// <summary>Array of Primary Key column names.</summary>
	  /// <remarks>Primary Key columns.</remarks>
    private static readonly string[] pkcolumns = { "OrderID" };
    /// <summary>Array of Database column names.</summary>
	  /// <remarks>Database column names.</remarks>
    private static readonly string[] columns = { "OrderID", "CustomerID", "OrderDate", "OrderAmount" };
    /// <summary>Array of DOM object properties.</summary>
	  /// <remarks>DOM object properties.</remarks>
    private static readonly string[] attributes = { "OrderID", "CustomerID", "OrderDate", "OrderAmount" };
    /// <summary>Array of Related Object names.</summary>
	  /// <remarks>Related Object names.</remarks>
    private static readonly string[] relations = { "Customer", "OrderItems" };

    private Type concreteObjectType = typeof(Order);

	  /// <summary>Property ObjectType.</summary>
	  /// <remarks>Returns the DOM's Type.</remarks>
	  /// <value>System.Type.</value>
    public override System.Type ObjectType
    {
        get { return typeof(Order); }
    }
    
    /// <summary>Property ObjectType.</summary>
	  /// <remarks>Returns the DOM's Type.</remarks>
	  /// <value>System.Type.</value>
    public override System.Type ConcreteObjectType
    {
        get { return concreteObjectType; }										 /* #custom# overridden */
        set { concreteObjectType = value; Factory.AddCustomType(value, this); }  /* #custom# overridden */
    }
    
    /// <summary>Property TableName.</summary>
	  /// <remarks>Returns database table name.</remarks>
	  /// <value>string.</value>
    public override string TableName
    {
        get { return "Orders"; }
    }
    
    /// <summary>Property PrimaryKeyColumns.</summary>
	/// <remarks>Array of Primary Key column names.</remarks>
	/// <value>string[].</value>
    public override string[] PrimaryKeyColumns
    {
        get { return pkcolumns; }
    }

	/// <summary>Property Columns.</summary>
	/// <remarks>Array of Database column names.</remarks>
	/// <value>string[].</value>
    public override string[] Columns
    {
        get { return columns; }
    }

	/// <summary>Property Attributes.</summary>
	/// <remarks>Array of DOM object properties.</remarks>
	/// <value>string[].</value>
    public override string[] Attributes
    {
        get { return attributes; }
    }

    /// <summary>Property Relations.</summary>
	/// <remarks>Array of Related Object names.</remarks>
	/// <value>string[].</value>
    public override string[] Relations
    {
        get { return relations; }
    }

	/// <summary>Generates a Hashtable, keyed by Object Name, or information regarding related objects.</summary>
	/// <remarks>Related Objects.</remarks>
	/// <returns>IDictionary.</returns>
  	protected override IDictionary GetRelationInfos()
    {
    	IDictionary infos = new Hashtable(2);
  		infos.Add("Customer", new RelationInfo(Factory, typeof(Customer), typeof(Order), "CustomerID", "CustomerID"));
 		infos.Add("OrderItems", new RelationInfo(Factory, typeof(Order), typeof(OrderItem), "OrderID", "OrderID"));
		return infos;    	
    }
    
	/// <summary>Based upon the model specified Id Method, returns the proper PkInitializer.</summary>
	/// <remarks>The object used to create a new PK value.</remarks>
	/// <returns>IPkInitializer.</returns>
	public override IPkInitializer GetPkInitializer()
	{
		return new NativePkInitializer();
	}
    
	/// <summary>Creates a new instance of Order.</summary>
	/// <remarks>Create new Order.</remarks>
	/// <param name="row">DataRow.</param>
	/// <param name="context">ObjectContext.</param>
	/// <returns>IEntityObject.</returns>
    public override IEntityObject CreateInstance(DataRow row, ObjectContext context) /* #custom# overridden */
    {
		if(ConcreteObjectType != ObjectType)
			return base.CreateInstance(row, context);
		return new Order(row, context);
	}
    
    /// <summary>Generates the in memory dataset.</summary>
	/// <remarks>Called by the Factory object.</remarks>
	/// <param name="table">DataTable.</param>
    protected override void WriteBasicSchema(DataTable table)
    {
		DataColumn		c;
		
		c = table.Columns.Add("OrderID", typeof(System.Int32));
		c.Unique = true;
		c.AutoIncrement = true; c.AutoIncrementSeed = c.AutoIncrementStep = -1;
		c = table.Columns.Add("CustomerID", typeof(System.Int32));
		c = table.Columns.Add("OrderDate", typeof(System.DateTime));
		c = table.Columns.Add("OrderAmount", typeof(System.Decimal));
		table.PrimaryKey = new DataColumn[] { table.Columns["OrderID"] };
	}
	
	/// <summary>Generates the dataset relationships.</summary>
	/// <remarks>Dataset Relationships.</remarks>
	/// <param name="table">DataTable.</param>
	protected override void WriteRelations(DataTable table)
	{
		DataRelation r;
		
		if(table.DataSet.Relations["Customers*Orders.CustomerID"] == null)
		{
			r = table.DataSet.Relations.Add("Customers*Orders.CustomerID", 
					table.DataSet.Tables["Customers"].Columns["CustomerID"],
					table.DataSet.Tables["Orders"].Columns["CustomerID"]);
			r.ChildKeyConstraint.UpdateRule = Rule.None;
			r.ChildKeyConstraint.DeleteRule = Rule.None;
		}
 		if(table.DataSet.Relations["Orders*OrderItems.OrderID"] == null)
		{
			r = table.DataSet.Relations.Add("Orders*OrderItems.OrderID", 
					table.DataSet.Tables["Orders"].Columns["OrderID"],
					table.DataSet.Tables["OrderItems"].Columns["OrderID"]);
			r.ChildKeyConstraint.UpdateRule = Rule.None;
			r.ChildKeyConstraint.DeleteRule = Rule.None;
		}
	}
}

#endregion

#region OrderSurrogateBase

/// <summary>Represents an entity object disconnected from the database.</summary>
/// <remarks>
///   <para>Database Path: CRMSample.Orders.</para>
/// </remarks>
[Serializable]
public abstract class OrderSurrogateBase : EntityObjectSurrogate
{
    /// <summary>Default constructor.</summary>
    public OrderSurrogateBase()
    {
    }
    
    /// <summary>
    /// Initializes a new instance of the <see cref="OrderSurrogateBase"/> class.
    /// </summary>
    /// <param name="entity">The entity.</param>
    public OrderSurrogateBase(Order entity)
    {
		OrderID = entity.OrderID;
		CustomerID = entity.CustomerID;
		OrderDate = entity.OrderDate;
		OrderAmount = entity.OrderAmount;
    }
    
    /// <summary>
    /// Updates the entity with the values contained within the surrogate.
    /// </summary>
    /// <param name="entity">The entity.</param>
    public void BindObjectInstance(Order entity)
    {
		if (entity.Row.RowState == DataRowState.Added)
        {
			entity.CustomerID = CustomerID;
			entity.OrderDate = OrderDate;
			entity.OrderAmount = OrderAmount;
		}
		else
		{
			if (_customeridHasBeenUpdated)
			{
				entity.CustomerID = CustomerID;
			}
			if (_orderdateHasBeenUpdated)
			{
				entity.OrderDate = OrderDate;
			}
			if (_orderamountHasBeenUpdated)
			{
				entity.OrderAmount = OrderAmount;
			}
		}
    }
    
    /// <summary>
    /// Property OrderItems </summary>
    /// <remarks> </remarks>
    /// <value> System.Collections.ArrayList </value>
    public System.Collections.ArrayList OrderItems
    {
    	get {return _orderitems;}
    	set {_orderitems = value;}
    }
		
	private System.Collections.ArrayList _orderitems;
	
	/// <summary>
    /// Property OrderID -  $attribute.Description </summary>
    /// <remarks> Database Path: CRMSample.Orders.OrderID.</remarks>
    /// <value> System.Int32. </value>
    public System.Int32? OrderID
    {
    	get {return _orderid;}
		set {_orderid = value;}
    }

	private System.Int32? _orderid;
	
	/// <summary>
    /// Property CustomerID - No Description </summary>
    /// <remarks> Database Path: CRMSample.Orders.CustomerID.</remarks>
    /// <value> System.Int32. </value>
    public System.Int32? CustomerID
    {
    	get {return _customerid;}
    	set {_customerid = value; _customeridHasBeenUpdated = true;}
    }

	private System.Int32? _customerid;
    private bool _customeridHasBeenUpdated;
	
	/// <summary>
    /// Property OrderDate -  $attribute.Description </summary>
    /// <remarks> Database Path: CRMSample.Orders.OrderDate.</remarks>
    /// <value> System.DateTime. </value>
    public System.DateTime? OrderDate
    {
    	get {return _orderdate;}
    	set {_orderdate = value; _orderdateHasBeenUpdated = true;}
    }

	private System.DateTime? _orderdate;
    private bool _orderdateHasBeenUpdated;
	
	/// <summary>
    /// Property OrderAmount -  $attribute.Description </summary>
    /// <remarks> Database Path: CRMSample.Orders.OrderAmount.</remarks>
    /// <value> System.Decimal. </value>
    public System.Decimal? OrderAmount
    {
    	get {return _orderamount;}
    	set {_orderamount = value; _orderamountHasBeenUpdated = true;}
    }

	private System.Decimal? _orderamount;
    private bool _orderamountHasBeenUpdated;
	
    /// <summary>
    /// Property Customer - gets or sets the Customer object with a one-to-one relationship to this instance.</summary>
    /// <remarks> Property Customer - gets or sets the Customer object with a one-to-one relationship to this instance.</remarks>
    /// <value> Customer. </value>
    public CustomerSurrogate Customer
    {
    	get {return _customer;}
    	set {_customer = value;}
    }

	private CustomerSurrogate _customer;
		

	/// <summary>
    /// Binds the surrogate values to the search template.
    /// </summary>
    /// <param name="emptyTemplate">The empty template.</param>
	public void BindToSearchTemplate(OrderTemplate emptyTemplate)
    {
        if (this.CustomerID != null)
            emptyTemplate.CustomerID = this.CustomerID.Value;
    }
    
	/// <summary>
	/// Determines whether this instance is valid.
	/// </summary>
	/// <returns>
	///	<c>true</c> if this instance is valid; otherwise, <c>false</c>.
	/// </returns>
    public abstract bool IsValid();

	/// <summary>
	/// Gets the validation message.
	/// </summary>
	/// <value>The validation message.</value>
    public abstract String ValidationMessage{get;}

}
#endregion

}

/* This is a customised template.
 * It overrides some optional methods from EntityMap to allow for testing 
 * with Mocks and fast object creation. Search for #custom# below. 
 */


namespace CRMSample.Models
{

#region Using statements

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using Neo.Core;
using Expergent;
using Expergent.Neo;
using Neo.Core.Util;
using Neo.Framework;

#endregion

#region OrderItemBase

/// <summary>
/// Generated table specific Base Class </summary>
/// <remarks> This class is generated by the Neo Framework. Make changes to NeoSupport.vtl.</remarks>
public partial class OrderItem : RulesEnabledEntityObject
{
       
	internal OrderItem(System.Data.DataRow aRow, Neo.Core.ObjectContext aContext) : base(aRow, aContext)
	{
	}
	
	/// <summary>
	/// Property OrderItemID -  $attribute.Description </summary>
	/// <remarks> Database Path: CRMSample.OrderItems.OrderItemID.</remarks>
	/// <value> System.Int32. </value>
	public virtual System.Int32? OrderItemID
	{
		get { object v = Row["OrderItemID"]; return (System.Int32?)((v != DBNull.Value) ? v : null); }
		set { if (value.HasValue) Row["OrderItemID"] = value; else Row["OrderItemID"] = DBNull.Value; }
	}    

	/// <summary>
	/// Property OrderID -  $attribute.Description </summary>
	/// <remarks> Database Path: CRMSample.OrderItems.OrderID.</remarks>
	/// <value> System.Int32. </value>
	public virtual System.Int32? OrderID
	{
		get { object v = Row["OrderID"]; return (System.Int32?)((v != DBNull.Value) ? v : null); }
		set { if (value.HasValue) Row["OrderID"] = value; else Row["OrderID"] = DBNull.Value; }
	}    

	/// <summary>
	/// Property ProductID - No Description </summary>
	/// <remarks> Database Path: CRMSample.OrderItems.ProductID.</remarks>
	/// <value> System.Guid. </value>
	public virtual System.Guid? ProductID
	{
		get { object v = Row["ProductID"]; return (System.Guid?)((v != DBNull.Value) ? v : null); }
		set { if (value.HasValue) Row["ProductID"] = value; else Row["ProductID"] = DBNull.Value; }
	}    

	/// <summary>
	/// Property Quantity -  $attribute.Description </summary>
	/// <remarks> Database Path: CRMSample.OrderItems.Quantity.</remarks>
	/// <value> System.Int32. </value>
	public virtual System.Int32? Quantity
	{
		get { object v = Row["Quantity"]; return (System.Int32?)((v != DBNull.Value) ? v : null); }
		set { if (value.HasValue) Row["Quantity"] = value; else Row["Quantity"] = DBNull.Value; }
	}    

	/// <summary>
	/// Property UnitPrice -  $attribute.Description </summary>
	/// <remarks> Database Path: CRMSample.OrderItems.UnitPrice.</remarks>
	/// <value> System.Decimal. </value>
	public virtual System.Decimal? UnitPrice
	{
		get { object v = Row["UnitPrice"]; return (System.Decimal?)((v != DBNull.Value) ? v : null); }
		set { if (value.HasValue) Row["UnitPrice"] = value; else Row["UnitPrice"] = DBNull.Value; }
	}    


	/// <summary>
	/// Property Order - gets or sets the Order object with a one-to-one relationship to this instance.</summary>
	/// <remarks> Property Order - gets or sets the Order object with a one-to-one relationship to this instance.</remarks>
	/// <value> Order. </value>
	public virtual Order Order
	{
		get { object fk = Row["OrderID"]; return (fk == DBNull.Value) ? null : (Order)GetRelatedObject("Orders", fk); }
		set { SetRelatedObject(value, "OrderID", "OrderID" ); }
	}

	/// <summary>
	/// Property Product - gets or sets the Product object with a one-to-one relationship to this instance.</summary>
	/// <remarks> Property Product - gets or sets the Product object with a one-to-one relationship to this instance.</remarks>
	/// <value> Product. </value>
	public virtual Product Product
	{
		get { object fk = Row["ProductID"]; return (fk == DBNull.Value) ? null : (Product)GetRelatedObject("Products", fk); }
		set { SetRelatedObject(value, "ProductID", "ProductID" ); }
	}

	/// <summary>
	/// Returns the value associated with the propName parameter.</summary>
	/// <remarks> You will need to cast the returned object into its native type upon return.</remarks>
	/// <param name="propName">String property name.</param>
	/// <returns> System.Object. </returns>
	public override object GetProperty(string propName)
	{
		if(propName == "OrderItemID") 
			return OrderItemID;
		if(propName == "OrderID") 
			return OrderID;
		if(propName == "ProductID") 
			return ProductID;
		if(propName == "Quantity") 
			return Quantity;
		if(propName == "UnitPrice") 
			return UnitPrice;
		if(propName == "Order") 
			return Order;
		if(propName == "Product") 
			return Product;
		return ExtendGetProperty(propName);
	}
	
	/// <summary>
    /// Sets the value associated with the propName parameter to the value specified.
    /// </summary>
    /// <param name="propName">String property name.</param>
    /// <param name="value">The value.</param>
	public override void SetProperty(string propName, object value)
	{
		if(propName == "OrderItemID") 
		{
			OrderItemID = (System.Int32?)value;
			return;
		}
		if(propName == "OrderID") 
		{
			OrderID = (System.Int32?)value;
			return;
		}
		if(propName == "ProductID") 
		{
			ProductID = (System.Guid?)value;
			return;
		}
		if(propName == "Quantity") 
		{
			Quantity = (System.Int32?)value;
			return;
		}
		if(propName == "UnitPrice") 
		{
			UnitPrice = (System.Decimal?)value;
			return;
		}
		if(propName == "Order") 
		{
			Order = (Order)value;
			return;
		}
		if(propName == "Product") 
		{
			Product = (Product)value;
			return;
		}
		ExtendSetProperty(propName, value);
	}


    /// <summary>
    /// Adds a set of facts for this instance to the list.
    /// </summary>
    /// <param name="list">The list.</param>
    /// <param name="parent">The parent.</param>
    protected override void MakeFacts(List<WME> list, string parent)
    {
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "OrderItemID"), OrderItemID));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "OrderID"), OrderID));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "ProductID"), ProductID));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "Quantity"), Quantity));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "UnitPrice"), UnitPrice));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "Order"), Order));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "Product"), Product));
        ExtendMakeFacts(list, parent);
        myFactsHaveBeenAsserted = true;
    }

	/// <summary>
    /// Populates the EntityObject from the specified surrogate.
    /// </summary>
    /// <param name="surrogate">The surrogate.</param>
	public void Populate(OrderItemSurrogate surrogate)
	{
		OrderID = surrogate.OrderID;
		ProductID = surrogate.ProductID;
		Quantity = surrogate.Quantity;
		UnitPrice = surrogate.UnitPrice;
	}
}

#endregion

#region OrderItemTemplate

/// <summary>
/// Generated table specific Query Template Class </summary>
/// <remarks> A Query Template for OrderItem operations. </remarks>
public class OrderItemTemplate : QueryTemplate
{

	/// <summary>
	/// Constructor </summary>
	/// <remarks> Public Constructor.</remarks>
	/// <param name="anEntityMap">IEntityMap instance.</param>
	public OrderItemTemplate(IEntityMap anEntityMap) : base(anEntityMap)
	{
	}
	
	/// <summary>
	/// Property OrderItemID -  $attributes.Description </summary>
	/// <remarks> Database Path: CRMSample.OrderItems.OrderItemID.</remarks>
	/// <value> System.Int32. </value>
	public System.Int32 OrderItemID
	{
		get { return (System.Int32)QueryValues["OrderItemID"]; }
		set { QueryValues["OrderItemID"] = value; }
	}

	/// <summary>
	/// Property OrderID -  $attributes.Description </summary>
	/// <remarks> Database Path: CRMSample.OrderItems.OrderID.</remarks>
	/// <value> System.Int32. </value>
	public System.Int32 OrderID
	{
		get { return (System.Int32)QueryValues["OrderID"]; }
		set { QueryValues["OrderID"] = value; }
	}

	/// <summary>
	/// Property ProductID - No Description </summary>
	/// <remarks> Database Path: CRMSample.OrderItems.ProductID.</remarks>
	/// <value> System.Guid. </value>
	public System.Guid ProductID
	{
		get { return (System.Guid)QueryValues["ProductID"]; }
		set { QueryValues["ProductID"] = value; }
	}

	/// <summary>
	/// Property Quantity -  $attributes.Description </summary>
	/// <remarks> Database Path: CRMSample.OrderItems.Quantity.</remarks>
	/// <value> System.Int32. </value>
	public System.Int32 Quantity
	{
		get { return (System.Int32)QueryValues["Quantity"]; }
		set { QueryValues["Quantity"] = value; }
	}

	/// <summary>
	/// Property UnitPrice -  $attributes.Description </summary>
	/// <remarks> Database Path: CRMSample.OrderItems.UnitPrice.</remarks>
	/// <value> System.Decimal. </value>
	public System.Decimal UnitPrice
	{
		get { return (System.Decimal)QueryValues["UnitPrice"]; }
		set { QueryValues["UnitPrice"] = value; }
	}

	/// <summary>
	/// Property Order - gets or sets the Order object with a one-to-one relationship to this instance.</summary>
	/// <remarks> Gets or sets the Order object.</remarks>
	/// <value> Order. </value>
	public Order Order
	{
		get { return (Order)QueryValues["Order"]; }
		set { QueryValues["Order"] = value; }
	}

	/// <summary>
	/// Property Product - gets or sets the Product object with a one-to-one relationship to this instance.</summary>
	/// <remarks> Gets or sets the Product object.</remarks>
	/// <value> Product. </value>
	public Product Product
	{
		get { return (Product)QueryValues["Product"]; }
		set { QueryValues["Product"] = value; }
	}

               
}

#endregion

#region OrderItemFactory

/// <summary>
/// Factory class for the creation of OrderItem objects.</summary>
/// <remarks> This class is generated by the Neo Framework. Make changes to NeoSupport.vtl.</remarks>
public class OrderItemFactory : Neo.Framework.ObjectFactory
{

	/// <summary>
	/// Constructor requiring an ObjectContext parameter.</summary>
	/// <remarks> Main entry point for the retrieval and creation of new OrderItem objects.</remarks>
	/// <param name="context">ObjectContext.</param>
	public OrderItemFactory(ObjectContext context) : base(context, typeof(OrderItem))
	{
	}

	/// <summary>
	/// Create new OrderItem object.</summary>
	/// <remarks>IdMethod = Native, PrimaryKeyIsForeignKey = False, RelationshipSetsForColumns = 0.</remarks>
	/// <returns> OrderItem </returns>
	public OrderItem CreateObject()
	{
		return (OrderItem)base.CreateObject(null);
	}
	

	/// <summary>
	/// Find a specified OrderItem object.</summary>
	/// <remarks> Requires Primary Key values and/or parent object instances.</remarks>
	/// <param name="arg0">$column.Description.</param>
	/// <returns> OrderItem </returns>
	public OrderItem FindObject(System.Int32 arg0)
	{
		return (OrderItem)base.FindObject(new object[] { arg0 } );
	}

	///<summary>
	///Find a specified OrderItem object.</summary>
	///<remarks> Requires Primary Key values and/or parent object instances.</remarks>
	///<param name="arg0">$column.Description.</param>
	///<returns> OrderItem </returns>
	public OrderItem FindObjectByPK( System.Int32 arg0 )
	{
		return (OrderItem) base.FindObject( new object[] {  arg0 } );
	}
	

	///<summary>
	///Find a specified OrderItem object.</summary>
	///<remarks> Requires Primary Key values and/or parent object instances.</remarks>
	///<param name="arg0">$column.Description.</param>
	///<returns> OrderItem </returns>
	public OrderItem FindObjectByPK( System.Int32? arg0 )
	{
		return (OrderItem) base.FindObject( new object[] {  arg0.Value } );
	}

	/// <summary>
	/// Find a list of OrderItem objects.</summary>
	/// <remarks> Returns all.</remarks>
	/// <returns> ObjectList&lt;OrderItem&gt; </returns>
	public new ObjectList<OrderItem> FindAllObjects()
	{
		ObjectList<OrderItem> c = new ObjectList<OrderItem>();
		foreach(OrderItem eo in base.FindAllObjects())
			c.Add(eo);
		return c;
	}
	
	/// <summary>
	/// Return the correct Query Template for the OrderItem object.</summary>
	/// <remarks> A query template is used for creating SQL like queries, in a more OO fashion.</remarks>
	/// <returns> OrderItemTemplate </returns>
	public OrderItemTemplate GetQueryTemplate()
	{
		return new OrderItemTemplate(EntityMap);
	}
	
	/// <summary>
	/// SQL like query to find and return a list of objects based on a template.</summary>
	/// <remarks> A query template is used for creating SQL like queries, in a more OO fashion.</remarks>
	/// <param name="template">OrderItemTemplate.</param>
	/// <returns> ObjectList&lt;OrderItem&gt; </returns>
	public ObjectList<OrderItem> Find(OrderItemTemplate template)
	{
		ObjectList<OrderItem> c = new ObjectList<OrderItem>();
		foreach(OrderItem eo in base.Find(template))
			c.Add(eo);
		return c;
	}

	/// <summary>
	/// SQL like query to find and return a list of objects based on a FetchSpecification.</summary>
	/// <remarks> A query Fetch Specification is used for creating SQL like queries, in a more OO fashion.</remarks>
	/// <param name="fetchSpecification">FetchSpecification.</param>
	/// <returns> ObjectList&lt;OrderItem&gt; </returns>
	public ObjectList<OrderItem> Find(FetchSpecification fetchSpecification)
	{
		ObjectList<OrderItem> c = new ObjectList<OrderItem>();
		foreach(OrderItem eo in base.Find(fetchSpecification))
			c.Add(eo);
		return c;
	}
	
	/// <summary>
	/// SQL like query to find and return a list of objects.</summary>
	/// <remarks> For example: ...Find("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> ObjectList&lt;OrderItem&gt; </returns>
	public new ObjectList<OrderItem> Find(string qualifierFormat, params object[] parameters)
	{
		ObjectList<OrderItem> c = new ObjectList<OrderItem>();
		foreach(OrderItem eo in base.Find(qualifierFormat, parameters))
			c.Add(eo);
		return c;
	}

	/// <summary>
	/// SQL like query to find and return a list of objects limiting the munber of items returned.</summary>
	/// <remarks> For example: ...Find(10, "TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="limit">Int32.</param>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> ObjectList&lt;OrderItem&gt; </returns>
	public new ObjectList<OrderItem> FindWithLimit(int limit, string qualifierFormat, params object[] parameters)
	{
		ObjectList<OrderItem> c = new ObjectList<OrderItem>();
		foreach(OrderItem eo in base.Find(qualifierFormat, parameters))
			c.Add(eo);
		return c;
	}
	
	/// <summary>
	/// SQL like query to find and return an object.</summary>
	/// <remarks> For example: ...FindFirst("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> OrderItem. </returns>
	public new OrderItem FindFirst(string qualifierFormat, params object[] parameters)
	{
		return (OrderItem)base.FindFirst(qualifierFormat, parameters);
	}

	/// <summary>
	/// SQL like query to find and return an object.</summary>
	/// <remarks> For example: ...FindUnique("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> OrderItem. </returns>
	public new OrderItem FindUnique(string qualifierFormat, params object[] parameters)
	{
		return (OrderItem)base.FindUnique(qualifierFormat, parameters);
	}	

	
}

#endregion

#region OrderItemEntityMap

//  -------- Entity Map -----------------------------------------------------
/// <summary>Creates the in memory version of the dataset for the OrderItem DOM.</summary>
/// <remarks>Generated by Neo Framework.</remarks>
internal class OrderItemMap : EntityMap
{
	  /// <summary>Array of Primary Key column names.</summary>
	  /// <remarks>Primary Key columns.</remarks>
    private static readonly string[] pkcolumns = { "OrderItemID" };
    /// <summary>Array of Database column names.</summary>
	  /// <remarks>Database column names.</remarks>
    private static readonly string[] columns = { "OrderItemID", "OrderID", "ProductID", "Quantity", "UnitPrice" };
    /// <summary>Array of DOM object properties.</summary>
	  /// <remarks>DOM object properties.</remarks>
    private static readonly string[] attributes = { "OrderItemID", "OrderID", "ProductID", "Quantity", "UnitPrice" };
    /// <summary>Array of Related Object names.</summary>
	  /// <remarks>Related Object names.</remarks>
    private static readonly string[] relations = { "Order", "Product" };

    private Type concreteObjectType = typeof(OrderItem);

	  /// <summary>Property ObjectType.</summary>
	  /// <remarks>Returns the DOM's Type.</remarks>
	  /// <value>System.Type.</value>
    public override System.Type ObjectType
    {
        get { return typeof(OrderItem); }
    }
    
    /// <summary>Property ObjectType.</summary>
	  /// <remarks>Returns the DOM's Type.</remarks>
	  /// <value>System.Type.</value>
    public override System.Type ConcreteObjectType
    {
        get { return concreteObjectType; }										 /* #custom# overridden */
        set { concreteObjectType = value; Factory.AddCustomType(value, this); }  /* #custom# overridden */
    }
    
    /// <summary>Property TableName.</summary>
	  /// <remarks>Returns database table name.</remarks>
	  /// <value>string.</value>
    public override string TableName
    {
        get { return "OrderItems"; }
    }
    
    /// <summary>Property PrimaryKeyColumns.</summary>
	/// <remarks>Array of Primary Key column names.</remarks>
	/// <value>string[].</value>
    public override string[] PrimaryKeyColumns
    {
        get { return pkcolumns; }
    }

	/// <summary>Property Columns.</summary>
	/// <remarks>Array of Database column names.</remarks>
	/// <value>string[].</value>
    public override string[] Columns
    {
        get { return columns; }
    }

	/// <summary>Property Attributes.</summary>
	/// <remarks>Array of DOM object properties.</remarks>
	/// <value>string[].</value>
    public override string[] Attributes
    {
        get { return attributes; }
    }

    /// <summary>Property Relations.</summary>
	/// <remarks>Array of Related Object names.</remarks>
	/// <value>string[].</value>
    public override string[] Relations
    {
        get { return relations; }
    }

	/// <summary>Generates a Hashtable, keyed by Object Name, or information regarding related objects.</summary>
	/// <remarks>Related Objects.</remarks>
	/// <returns>IDictionary.</returns>
  	protected override IDictionary GetRelationInfos()
    {
    	IDictionary infos = new Hashtable(2);
  		infos.Add("Order", new RelationInfo(Factory, typeof(Order), typeof(OrderItem), "OrderID", "OrderID"));
 		infos.Add("Product", new RelationInfo(Factory, typeof(Product), typeof(OrderItem), "ProductID", "ProductID"));
		return infos;    	
    }
    
	/// <summary>Based upon the model specified Id Method, returns the proper PkInitializer.</summary>
	/// <remarks>The object used to create a new PK value.</remarks>
	/// <returns>IPkInitializer.</returns>
	public override IPkInitializer GetPkInitializer()
	{
		return new NativePkInitializer();
	}
    
	/// <summary>Creates a new instance of OrderItem.</summary>
	/// <remarks>Create new OrderItem.</remarks>
	/// <param name="row">DataRow.</param>
	/// <param name="context">ObjectContext.</param>
	/// <returns>IEntityObject.</returns>
    public override IEntityObject CreateInstance(DataRow row, ObjectContext context) /* #custom# overridden */
    {
		if(ConcreteObjectType != ObjectType)
			return base.CreateInstance(row, context);
		return new OrderItem(row, context);
	}
    
    /// <summary>Generates the in memory dataset.</summary>
	/// <remarks>Called by the Factory object.</remarks>
	/// <param name="table">DataTable.</param>
    protected override void WriteBasicSchema(DataTable table)
    {
		DataColumn		c;
		
		c = table.Columns.Add("OrderItemID", typeof(System.Int32));
		c.Unique = true;
		c.AutoIncrement = true; c.AutoIncrementSeed = c.AutoIncrementStep = -1;
		c = table.Columns.Add("OrderID", typeof(System.Int32));
		c = table.Columns.Add("ProductID", typeof(System.Guid));
		c = table.Columns.Add("Quantity", typeof(System.Int32));
		c = table.Columns.Add("UnitPrice", typeof(System.Decimal));
		table.PrimaryKey = new DataColumn[] { table.Columns["OrderItemID"] };
	}
	
	/// <summary>Generates the dataset relationships.</summary>
	/// <remarks>Dataset Relationships.</remarks>
	/// <param name="table">DataTable.</param>
	protected override void WriteRelations(DataTable table)
	{
		DataRelation r;
		
		if(table.DataSet.Relations["Orders*OrderItems.OrderID"] == null)
		{
			r = table.DataSet.Relations.Add("Orders*OrderItems.OrderID", 
					table.DataSet.Tables["Orders"].Columns["OrderID"],
					table.DataSet.Tables["OrderItems"].Columns["OrderID"]);
			r.ChildKeyConstraint.UpdateRule = Rule.None;
			r.ChildKeyConstraint.DeleteRule = Rule.None;
		}
		if(table.DataSet.Relations["Products*OrderItems.ProductID"] == null)
		{
			r = table.DataSet.Relations.Add("Products*OrderItems.ProductID", 
					table.DataSet.Tables["Products"].Columns["ProductID"],
					table.DataSet.Tables["OrderItems"].Columns["ProductID"]);
			r.ChildKeyConstraint.UpdateRule = Rule.None;
			r.ChildKeyConstraint.DeleteRule = Rule.None;
		}
	}
}

#endregion

#region OrderItemSurrogateBase

/// <summary>Represents an entity object disconnected from the database.</summary>
/// <remarks>
///   <para>Database Path: CRMSample.OrderItems.</para>
/// </remarks>
[Serializable]
public abstract class OrderItemSurrogateBase : EntityObjectSurrogate
{
    /// <summary>Default constructor.</summary>
    public OrderItemSurrogateBase()
    {
    }
    
    /// <summary>
    /// Initializes a new instance of the <see cref="OrderItemSurrogateBase"/> class.
    /// </summary>
    /// <param name="entity">The entity.</param>
    public OrderItemSurrogateBase(OrderItem entity)
    {
		OrderItemID = entity.OrderItemID;
		OrderID = entity.OrderID;
		ProductID = entity.ProductID;
		Quantity = entity.Quantity;
		UnitPrice = entity.UnitPrice;
    }
    
    /// <summary>
    /// Updates the entity with the values contained within the surrogate.
    /// </summary>
    /// <param name="entity">The entity.</param>
    public void BindObjectInstance(OrderItem entity)
    {
		if (entity.Row.RowState == DataRowState.Added)
        {
			entity.OrderID = OrderID;
			entity.ProductID = ProductID;
			entity.Quantity = Quantity;
			entity.UnitPrice = UnitPrice;
		}
		else
		{
			if (_orderidHasBeenUpdated)
			{
				entity.OrderID = OrderID;
			}
			if (_productidHasBeenUpdated)
			{
				entity.ProductID = ProductID;
			}
			if (_quantityHasBeenUpdated)
			{
				entity.Quantity = Quantity;
			}
			if (_unitpriceHasBeenUpdated)
			{
				entity.UnitPrice = UnitPrice;
			}
		}
    }
    
	/// <summary>
    /// Property OrderItemID -  $attribute.Description </summary>
    /// <remarks> Database Path: CRMSample.OrderItems.OrderItemID.</remarks>
    /// <value> System.Int32. </value>
    public System.Int32? OrderItemID
    {
    	get {return _orderitemid;}
		set {_orderitemid = value;}
    }

	private System.Int32? _orderitemid;
	
	/// <summary>
    /// Property OrderID -  $attribute.Description </summary>
    /// <remarks> Database Path: CRMSample.OrderItems.OrderID.</remarks>
    /// <value> System.Int32. </value>
    public System.Int32? OrderID
    {
    	get {return _orderid;}
    	set {_orderid = value; _orderidHasBeenUpdated = true;}
    }

	private System.Int32? _orderid;
    private bool _orderidHasBeenUpdated;
	
	/// <summary>
    /// Property ProductID - No Description </summary>
    /// <remarks> Database Path: CRMSample.OrderItems.ProductID.</remarks>
    /// <value> System.Guid. </value>
    public System.Guid? ProductID
    {
    	get {return _productid;}
    	set {_productid = value; _productidHasBeenUpdated = true;}
    }

	private System.Guid? _productid;
    private bool _productidHasBeenUpdated;
	
	/// <summary>
    /// Property Quantity -  $attribute.Description </summary>
    /// <remarks> Database Path: CRMSample.OrderItems.Quantity.</remarks>
    /// <value> System.Int32. </value>
    public System.Int32? Quantity
    {
    	get {return _quantity;}
    	set {_quantity = value; _quantityHasBeenUpdated = true;}
    }

	private System.Int32? _quantity;
    private bool _quantityHasBeenUpdated;
	
	/// <summary>
    /// Property UnitPrice -  $attribute.Description </summary>
    /// <remarks> Database Path: CRMSample.OrderItems.UnitPrice.</remarks>
    /// <value> System.Decimal. </value>
    public System.Decimal? UnitPrice
    {
    	get {return _unitprice;}
    	set {_unitprice = value; _unitpriceHasBeenUpdated = true;}
    }

	private System.Decimal? _unitprice;
    private bool _unitpriceHasBeenUpdated;
	
    /// <summary>
    /// Property Order - gets or sets the Order object with a one-to-one relationship to this instance.</summary>
    /// <remarks> Property Order - gets or sets the Order object with a one-to-one relationship to this instance.</remarks>
    /// <value> Order. </value>
    public OrderSurrogate Order
    {
    	get {return _order;}
    	set {_order = value;}
    }

	private OrderSurrogate _order;
		
    /// <summary>
    /// Property Product - gets or sets the Product object with a one-to-one relationship to this instance.</summary>
    /// <remarks> Property Product - gets or sets the Product object with a one-to-one relationship to this instance.</remarks>
    /// <value> Product. </value>
    public ProductSurrogate Product
    {
    	get {return _product;}
    	set {_product = value;}
    }

	private ProductSurrogate _product;
		

	/// <summary>
    /// Binds the surrogate values to the search template.
    /// </summary>
    /// <param name="emptyTemplate">The empty template.</param>
	public void BindToSearchTemplate(OrderItemTemplate emptyTemplate)
    {
        if (this.OrderID != null)
            emptyTemplate.OrderID = this.OrderID.Value;
        if (this.ProductID != null)
            emptyTemplate.ProductID = this.ProductID.Value;
    }
    
	/// <summary>
	/// Determines whether this instance is valid.
	/// </summary>
	/// <returns>
	///	<c>true</c> if this instance is valid; otherwise, <c>false</c>.
	/// </returns>
    public abstract bool IsValid();

	/// <summary>
	/// Gets the validation message.
	/// </summary>
	/// <value>The validation message.</value>
    public abstract String ValidationMessage{get;}

}
#endregion

}

/* This is a customised template.
 * It overrides some optional methods from EntityMap to allow for testing 
 * with Mocks and fast object creation. Search for #custom# below. 
 */


namespace CRMSample.Models
{

#region Using statements

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using Neo.Core;
using Expergent;
using Expergent.Neo;
using Neo.Core.Util;
using Neo.Framework;

#endregion

#region ProductBase

/// <summary>
/// Generated table specific Base Class </summary>
/// <remarks> This class is generated by the Neo Framework. Make changes to NeoSupport.vtl.</remarks>
public partial class Product : RulesEnabledEntityObject
{
	/// <summary>
	/// A collection of Inventory objects referencing this instance.</summary>
	/// <remarks> Objects referencing this instance.</remarks>
	public readonly ObjectRelation<Inventory> Inventory;
	/// <summary>
	/// A collection of OrderItem objects referencing this instance.</summary>
	/// <remarks> Objects referencing this instance.</remarks>
	public readonly ObjectRelation<OrderItem> OrderItems;
       
	internal Product(System.Data.DataRow aRow, Neo.Core.ObjectContext aContext) : base(aRow, aContext)
	{
		Inventory = new ObjectRelation<Inventory>(this, "Inventory");
		OrderItems = new ObjectRelation<OrderItem>(this, "OrderItems");
	}
	
	/// <summary>
	/// Property ProductID -  $attribute.Description </summary>
	/// <remarks> Database Path: CRMSample.Products.ProductID.</remarks>
	/// <value> System.Guid. </value>
	public virtual System.Guid? ProductID
	{
		get { object v = Row["ProductID"]; return (System.Guid?)((v != DBNull.Value) ? v : null); }
		set { if (value.HasValue) Row["ProductID"] = value; else Row["ProductID"] = DBNull.Value; }
	}    

	/// <summary>
	/// Property Description - No Description </summary>
	/// <remarks> Database Path: CRMSample.Products.Description.</remarks>
	/// <value> System.String. </value>
	public virtual System.String Description
	{
		get { return Row["Description"] as System.String; }
		set { Row["Description"] = (value != null) ? (object)value : (object)DBNull.Value; }
	}    

	/// <summary>
	/// Property Supplier - No Description </summary>
	/// <remarks> Database Path: CRMSample.Products.Supplier.</remarks>
	/// <value> System.String. </value>
	public virtual System.String Supplier
	{
		get { return Row["Supplier"] as System.String; }
		set { Row["Supplier"] = (value != null) ? (object)value : (object)DBNull.Value; }
	}    


	/// <summary>
	/// Returns the value associated with the propName parameter.</summary>
	/// <remarks> You will need to cast the returned object into its native type upon return.</remarks>
	/// <param name="propName">String property name.</param>
	/// <returns> System.Object. </returns>
	public override object GetProperty(string propName)
	{
		if(propName == "ProductID") 
			return ProductID;
		if(propName == "Description") 
			return Description;
		if(propName == "Supplier") 
			return Supplier;
		if(propName == "Inventory") 
			return Inventory;
		if(propName == "OrderItems") 
			return OrderItems;
		return ExtendGetProperty(propName);
	}
	
	/// <summary>
    /// Sets the value associated with the propName parameter to the value specified.
    /// </summary>
    /// <param name="propName">String property name.</param>
    /// <param name="value">The value.</param>
	public override void SetProperty(string propName, object value)
	{
		if(propName == "ProductID") 
		{
			ProductID = (System.Guid?)value;
			return;
		}
		if(propName == "Description") 
		{
			Description = (System.String)value;
			return;
		}
		if(propName == "Supplier") 
		{
			Supplier = (System.String)value;
			return;
		}
		ExtendSetProperty(propName, value);
	}

    /// <summary>
    /// Ensures related tables are loaded into memory for a cascaded delete.</summary>
    /// <remarks> Deletes related tables entries when cascade is specified.</remarks>
    public override void Delete() 
    {
        Inventory.Touch();
        while (Inventory.Count > 0)
        {
            Inventory[0].Delete();
        }
        OrderItems.Touch();
        while (OrderItems.Count > 0)
        {
            OrderItems[0].Delete();
        }
        base.Delete();
    }

    /// <summary>
    /// Adds a set of facts for this instance to the list.
    /// </summary>
    /// <param name="list">The list.</param>
    /// <param name="parent">The parent.</param>
    protected override void MakeFacts(List<WME> list, string parent)
    {
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "ProductID"), ProductID));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "Description"), Description));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "Supplier"), Supplier));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "Inventory"), Inventory));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "OrderItems"), OrderItems));
        ExtendMakeFacts(list, parent);
        myFactsHaveBeenAsserted = true;
    }

	/// <summary>
    /// Populates the EntityObject from the specified surrogate.
    /// </summary>
    /// <param name="surrogate">The surrogate.</param>
	public void Populate(ProductSurrogate surrogate)
	{
		Description = surrogate.Description;
		Supplier = surrogate.Supplier;
	}
}

#endregion

#region ProductTemplate

/// <summary>
/// Generated table specific Query Template Class </summary>
/// <remarks> A Query Template for Product operations. </remarks>
public class ProductTemplate : QueryTemplate
{

	/// <summary>
	/// Constructor </summary>
	/// <remarks> Public Constructor.</remarks>
	/// <param name="anEntityMap">IEntityMap instance.</param>
	public ProductTemplate(IEntityMap anEntityMap) : base(anEntityMap)
	{
	}
	
	/// <summary>
	/// Property ProductID -  $attributes.Description </summary>
	/// <remarks> Database Path: CRMSample.Products.ProductID.</remarks>
	/// <value> System.Guid. </value>
	public System.Guid ProductID
	{
		get { return (System.Guid)QueryValues["ProductID"]; }
		set { QueryValues["ProductID"] = value; }
	}

	/// <summary>
	/// Property Description - No Description </summary>
	/// <remarks> Database Path: CRMSample.Products.Description.</remarks>
	/// <value> System.String. </value>
	public System.String Description
	{
		get { return (System.String)QueryValues["Description"]; }
		set { QueryValues["Description"] = value; }
	}

	/// <summary>
	/// Property Supplier - No Description </summary>
	/// <remarks> Database Path: CRMSample.Products.Supplier.</remarks>
	/// <value> System.String. </value>
	public System.String Supplier
	{
		get { return (System.String)QueryValues["Supplier"]; }
		set { QueryValues["Supplier"] = value; }
	}

               
}

#endregion

#region ProductFactory

/// <summary>
/// Factory class for the creation of Product objects.</summary>
/// <remarks> This class is generated by the Neo Framework. Make changes to NeoSupport.vtl.</remarks>
public class ProductFactory : Neo.Framework.ObjectFactory
{

	/// <summary>
	/// Constructor requiring an ObjectContext parameter.</summary>
	/// <remarks> Main entry point for the retrieval and creation of new Product objects.</remarks>
	/// <param name="context">ObjectContext.</param>
	public ProductFactory(ObjectContext context) : base(context, typeof(Product))
	{
	}

	/// <summary>
	/// Create new Product object.</summary>
	/// <remarks>IdMethod = Guid, PrimaryKeyIsForeignKey = False, RelationshipSetsForColumns = 2.</remarks>
	/// <returns> Product </returns>
	public Product CreateObject()
	{
		return (Product)base.CreateObject(null);
	}
	

	/// <summary>
	/// Find a specified Product object.</summary>
	/// <remarks> Requires Primary Key values and/or parent object instances.</remarks>
	/// <param name="arg0">$column.Description.</param>
	/// <returns> Product </returns>
	public Product FindObject(System.Guid arg0)
	{
		return (Product)base.FindObject(new object[] { arg0 } );
	}

	///<summary>
	///Find a specified Product object.</summary>
	///<remarks> Requires Primary Key values and/or parent object instances.</remarks>
	///<param name="arg0">$column.Description.</param>
	///<returns> Product </returns>
	public Product FindObjectByPK( System.Guid arg0 )
	{
		return (Product) base.FindObject( new object[] {  arg0 } );
	}
	

	///<summary>
	///Find a specified Product object.</summary>
	///<remarks> Requires Primary Key values and/or parent object instances.</remarks>
	///<param name="arg0">$column.Description.</param>
	///<returns> Product </returns>
	public Product FindObjectByPK( System.Guid? arg0 )
	{
		return (Product) base.FindObject( new object[] {  arg0.Value } );
	}

	/// <summary>
	/// Find a list of Product objects.</summary>
	/// <remarks> Returns all.</remarks>
	/// <returns> ObjectList&lt;Product&gt; </returns>
	public new ObjectList<Product> FindAllObjects()
	{
		ObjectList<Product> c = new ObjectList<Product>();
		foreach(Product eo in base.FindAllObjects())
			c.Add(eo);
		return c;
	}
	
	/// <summary>
	/// Return the correct Query Template for the Product object.</summary>
	/// <remarks> A query template is used for creating SQL like queries, in a more OO fashion.</remarks>
	/// <returns> ProductTemplate </returns>
	public ProductTemplate GetQueryTemplate()
	{
		return new ProductTemplate(EntityMap);
	}
	
	/// <summary>
	/// SQL like query to find and return a list of objects based on a template.</summary>
	/// <remarks> A query template is used for creating SQL like queries, in a more OO fashion.</remarks>
	/// <param name="template">ProductTemplate.</param>
	/// <returns> ObjectList&lt;Product&gt; </returns>
	public ObjectList<Product> Find(ProductTemplate template)
	{
		ObjectList<Product> c = new ObjectList<Product>();
		foreach(Product eo in base.Find(template))
			c.Add(eo);
		return c;
	}

	/// <summary>
	/// SQL like query to find and return a list of objects based on a FetchSpecification.</summary>
	/// <remarks> A query Fetch Specification is used for creating SQL like queries, in a more OO fashion.</remarks>
	/// <param name="fetchSpecification">FetchSpecification.</param>
	/// <returns> ObjectList&lt;Product&gt; </returns>
	public ObjectList<Product> Find(FetchSpecification fetchSpecification)
	{
		ObjectList<Product> c = new ObjectList<Product>();
		foreach(Product eo in base.Find(fetchSpecification))
			c.Add(eo);
		return c;
	}
	
	/// <summary>
	/// SQL like query to find and return a list of objects.</summary>
	/// <remarks> For example: ...Find("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> ObjectList&lt;Product&gt; </returns>
	public new ObjectList<Product> Find(string qualifierFormat, params object[] parameters)
	{
		ObjectList<Product> c = new ObjectList<Product>();
		foreach(Product eo in base.Find(qualifierFormat, parameters))
			c.Add(eo);
		return c;
	}

	/// <summary>
	/// SQL like query to find and return a list of objects limiting the munber of items returned.</summary>
	/// <remarks> For example: ...Find(10, "TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="limit">Int32.</param>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> ObjectList&lt;Product&gt; </returns>
	public new ObjectList<Product> FindWithLimit(int limit, string qualifierFormat, params object[] parameters)
	{
		ObjectList<Product> c = new ObjectList<Product>();
		foreach(Product eo in base.Find(qualifierFormat, parameters))
			c.Add(eo);
		return c;
	}
	
	/// <summary>
	/// SQL like query to find and return an object.</summary>
	/// <remarks> For example: ...FindFirst("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> Product. </returns>
	public new Product FindFirst(string qualifierFormat, params object[] parameters)
	{
		return (Product)base.FindFirst(qualifierFormat, parameters);
	}

	/// <summary>
	/// SQL like query to find and return an object.</summary>
	/// <remarks> For example: ...FindUnique("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> Product. </returns>
	public new Product FindUnique(string qualifierFormat, params object[] parameters)
	{
		return (Product)base.FindUnique(qualifierFormat, parameters);
	}	

	
}

#endregion

#region ProductEntityMap

//  -------- Entity Map -----------------------------------------------------
/// <summary>Creates the in memory version of the dataset for the Product DOM.</summary>
/// <remarks>Generated by Neo Framework.</remarks>
internal class ProductMap : EntityMap
{
	  /// <summary>Array of Primary Key column names.</summary>
	  /// <remarks>Primary Key columns.</remarks>
    private static readonly string[] pkcolumns = { "ProductID" };
    /// <summary>Array of Database column names.</summary>
	  /// <remarks>Database column names.</remarks>
    private static readonly string[] columns = { "ProductID", "Description", "Supplier" };
    /// <summary>Array of DOM object properties.</summary>
	  /// <remarks>DOM object properties.</remarks>
    private static readonly string[] attributes = { "ProductID", "Description", "Supplier" };
    /// <summary>Array of Related Object names.</summary>
	  /// <remarks>Related Object names.</remarks>
    private static readonly string[] relations = { "Inventory", "OrderItems" };

    private Type concreteObjectType = typeof(Product);

	  /// <summary>Property ObjectType.</summary>
	  /// <remarks>Returns the DOM's Type.</remarks>
	  /// <value>System.Type.</value>
    public override System.Type ObjectType
    {
        get { return typeof(Product); }
    }
    
    /// <summary>Property ObjectType.</summary>
	  /// <remarks>Returns the DOM's Type.</remarks>
	  /// <value>System.Type.</value>
    public override System.Type ConcreteObjectType
    {
        get { return concreteObjectType; }										 /* #custom# overridden */
        set { concreteObjectType = value; Factory.AddCustomType(value, this); }  /* #custom# overridden */
    }
    
    /// <summary>Property TableName.</summary>
	  /// <remarks>Returns database table name.</remarks>
	  /// <value>string.</value>
    public override string TableName
    {
        get { return "Products"; }
    }
    
    /// <summary>Property PrimaryKeyColumns.</summary>
	/// <remarks>Array of Primary Key column names.</remarks>
	/// <value>string[].</value>
    public override string[] PrimaryKeyColumns
    {
        get { return pkcolumns; }
    }

	/// <summary>Property Columns.</summary>
	/// <remarks>Array of Database column names.</remarks>
	/// <value>string[].</value>
    public override string[] Columns
    {
        get { return columns; }
    }

	/// <summary>Property Attributes.</summary>
	/// <remarks>Array of DOM object properties.</remarks>
	/// <value>string[].</value>
    public override string[] Attributes
    {
        get { return attributes; }
    }

    /// <summary>Property Relations.</summary>
	/// <remarks>Array of Related Object names.</remarks>
	/// <value>string[].</value>
    public override string[] Relations
    {
        get { return relations; }
    }

	/// <summary>Generates a Hashtable, keyed by Object Name, or information regarding related objects.</summary>
	/// <remarks>Related Objects.</remarks>
	/// <returns>IDictionary.</returns>
  	protected override IDictionary GetRelationInfos()
    {
    	IDictionary infos = new Hashtable(2);
  		infos.Add("Inventory", new RelationInfo(Factory, typeof(Product), typeof(Inventory), "ProductID", "ProductID"));
 		infos.Add("OrderItems", new RelationInfo(Factory, typeof(Product), typeof(OrderItem), "ProductID", "ProductID"));
		return infos;    	
    }
    
	/// <summary>Based upon the model specified Id Method, returns the proper PkInitializer.</summary>
	/// <remarks>The object used to create a new PK value.</remarks>
	/// <returns>IPkInitializer.</returns>
	public override IPkInitializer GetPkInitializer()
	{
		return new GuidPkInitializer();
	}
    
	/// <summary>Creates a new instance of Product.</summary>
	/// <remarks>Create new Product.</remarks>
	/// <param name="row">DataRow.</param>
	/// <param name="context">ObjectContext.</param>
	/// <returns>IEntityObject.</returns>
    public override IEntityObject CreateInstance(DataRow row, ObjectContext context) /* #custom# overridden */
    {
		if(ConcreteObjectType != ObjectType)
			return base.CreateInstance(row, context);
		return new Product(row, context);
	}
    
    /// <summary>Generates the in memory dataset.</summary>
	/// <remarks>Called by the Factory object.</remarks>
	/// <param name="table">DataTable.</param>
    protected override void WriteBasicSchema(DataTable table)
    {
		DataColumn		c;
		
		c = table.Columns.Add("ProductID", typeof(System.Guid));
		c.Unique = true;
		c = table.Columns.Add("Description", typeof(System.String));
		c = table.Columns.Add("Supplier", typeof(System.String));
		table.PrimaryKey = new DataColumn[] { table.Columns["ProductID"] };
	}
	
	/// <summary>Generates the dataset relationships.</summary>
	/// <remarks>Dataset Relationships.</remarks>
	/// <param name="table">DataTable.</param>
	protected override void WriteRelations(DataTable table)
	{
		DataRelation r;
		
 		if(table.DataSet.Relations["Products*Inventory.ProductID"] == null)
		{
			r = table.DataSet.Relations.Add("Products*Inventory.ProductID", 
					table.DataSet.Tables["Products"].Columns["ProductID"],
					table.DataSet.Tables["Inventory"].Columns["ProductID"]);
			r.ChildKeyConstraint.UpdateRule = Rule.None;
			r.ChildKeyConstraint.DeleteRule = Rule.None;
		}
 		if(table.DataSet.Relations["Products*OrderItems.ProductID"] == null)
		{
			r = table.DataSet.Relations.Add("Products*OrderItems.ProductID", 
					table.DataSet.Tables["Products"].Columns["ProductID"],
					table.DataSet.Tables["OrderItems"].Columns["ProductID"]);
			r.ChildKeyConstraint.UpdateRule = Rule.None;
			r.ChildKeyConstraint.DeleteRule = Rule.None;
		}
	}
}

#endregion

#region ProductSurrogateBase

/// <summary>Represents an entity object disconnected from the database.</summary>
/// <remarks>
///   <para>Database Path: CRMSample.Products.</para>
/// </remarks>
[Serializable]
public abstract class ProductSurrogateBase : EntityObjectSurrogate
{
    /// <summary>Default constructor.</summary>
    public ProductSurrogateBase()
    {
    }
    
    /// <summary>
    /// Initializes a new instance of the <see cref="ProductSurrogateBase"/> class.
    /// </summary>
    /// <param name="entity">The entity.</param>
    public ProductSurrogateBase(Product entity)
    {
		ProductID = entity.ProductID;
		Description = entity.Description;
		Supplier = entity.Supplier;
    }
    
    /// <summary>
    /// Updates the entity with the values contained within the surrogate.
    /// </summary>
    /// <param name="entity">The entity.</param>
    public void BindObjectInstance(Product entity)
    {
		if (entity.Row.RowState == DataRowState.Added)
        {
			entity.Description = Description;
			entity.Supplier = Supplier;
		}
		else
		{
			if (_descriptionHasBeenUpdated)
			{
				entity.Description = Description;
			}
			if (_supplierHasBeenUpdated)
			{
				entity.Supplier = Supplier;
			}
		}
    }
    
    /// <summary>
    /// Property Inventory </summary>
    /// <remarks> </remarks>
    /// <value> System.Collections.ArrayList </value>
    public System.Collections.ArrayList Inventory
    {
    	get {return _inventory;}
    	set {_inventory = value;}
    }
		
	private System.Collections.ArrayList _inventory;
	
    /// <summary>
    /// Property OrderItems </summary>
    /// <remarks> </remarks>
    /// <value> System.Collections.ArrayList </value>
    public System.Collections.ArrayList OrderItems
    {
    	get {return _orderitems;}
    	set {_orderitems = value;}
    }
		
	private System.Collections.ArrayList _orderitems;
	
	/// <summary>
    /// Property ProductID -  $attribute.Description </summary>
    /// <remarks> Database Path: CRMSample.Products.ProductID.</remarks>
    /// <value> System.Guid. </value>
    public System.Guid? ProductID
    {
    	get {return _productid;}
		set {_productid = value;}
    }

	private System.Guid? _productid;
	
    /// <summary>
    /// Property Description - No Description </summary>
    /// <remarks> Database Path: CRMSample.Products.Description.</remarks>
    /// <value> System.String. </value>
    public System.String Description
    {
    	get {return _description;}
    	set {_description = value; _descriptionHasBeenUpdated = true;}
    }

	private System.String _description;
    private bool _descriptionHasBeenUpdated;
	
    /// <summary>
    /// Property Supplier - No Description </summary>
    /// <remarks> Database Path: CRMSample.Products.Supplier.</remarks>
    /// <value> System.String. </value>
    public System.String Supplier
    {
    	get {return _supplier;}
    	set {_supplier = value; _supplierHasBeenUpdated = true;}
    }

	private System.String _supplier;
    private bool _supplierHasBeenUpdated;
	

	/// <summary>
    /// Binds the surrogate values to the search template.
    /// </summary>
    /// <param name="emptyTemplate">The empty template.</param>
	public void BindToSearchTemplate(ProductTemplate emptyTemplate)
    {
    }
    
	/// <summary>
	/// Determines whether this instance is valid.
	/// </summary>
	/// <returns>
	///	<c>true</c> if this instance is valid; otherwise, <c>false</c>.
	/// </returns>
    public abstract bool IsValid();

	/// <summary>
	/// Gets the validation message.
	/// </summary>
	/// <value>The validation message.</value>
    public abstract String ValidationMessage{get;}

}
#endregion

}

/* This is a customised template.
 * It overrides some optional methods from EntityMap to allow for testing 
 * with Mocks and fast object creation. Search for #custom# below. 
 */


namespace CRMSample.Models
{

#region Using statements

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using Neo.Core;
using Expergent;
using Expergent.Neo;
using Neo.Core.Util;
using Neo.Framework;

#endregion

#region InventoryBase

/// <summary>
/// Generated table specific Base Class </summary>
/// <remarks> This class is generated by the Neo Framework. Make changes to NeoSupport.vtl.</remarks>
public partial class Inventory : RulesEnabledEntityObject
{
       
	internal Inventory(System.Data.DataRow aRow, Neo.Core.ObjectContext aContext) : base(aRow, aContext)
	{
	}
	
	/// <summary>
	/// Property InventoryID -  $attribute.Description </summary>
	/// <remarks> Database Path: CRMSample.Inventory.InventoryID.</remarks>
	/// <value> System.Guid. </value>
	public virtual System.Guid? InventoryID
	{
		get { object v = Row["InventoryID"]; return (System.Guid?)((v != DBNull.Value) ? v : null); }
		set { if (value.HasValue) Row["InventoryID"] = value; else Row["InventoryID"] = DBNull.Value; }
	}    

	/// <summary>
	/// Property ProductID -  $attribute.Description </summary>
	/// <remarks> Database Path: CRMSample.Inventory.ProductID.</remarks>
	/// <value> System.Guid. </value>
	public virtual System.Guid? ProductID
	{
		get { object v = Row["ProductID"]; return (System.Guid?)((v != DBNull.Value) ? v : null); }
		set { if (value.HasValue) Row["ProductID"] = value; else Row["ProductID"] = DBNull.Value; }
	}    

	/// <summary>
	/// Property StockOnHand -  $attribute.Description </summary>
	/// <remarks> Database Path: CRMSample.Inventory.StockOnHand.</remarks>
	/// <value> System.Int32. </value>
	public virtual System.Int32? StockOnHand
	{
		get { object v = Row["StockOnHand"]; return (System.Int32?)((v != DBNull.Value) ? v : null); }
		set { if (value.HasValue) Row["StockOnHand"] = value; else Row["StockOnHand"] = DBNull.Value; }
	}    


	/// <summary>
	/// Property Products - gets or sets the Product object with a one-to-one relationship to this instance.</summary>
	/// <remarks> Property Products - gets or sets the Product object with a one-to-one relationship to this instance.</remarks>
	/// <value> Product. </value>
	public virtual Product Products
	{
		get { object fk = Row["ProductID"]; return (fk == DBNull.Value) ? null : (Product)GetRelatedObject("Products", fk); }
		set { SetRelatedObject(value, "ProductID", "ProductID" ); }
	}

	/// <summary>
	/// Returns the value associated with the propName parameter.</summary>
	/// <remarks> You will need to cast the returned object into its native type upon return.</remarks>
	/// <param name="propName">String property name.</param>
	/// <returns> System.Object. </returns>
	public override object GetProperty(string propName)
	{
		if(propName == "InventoryID") 
			return InventoryID;
		if(propName == "ProductID") 
			return ProductID;
		if(propName == "StockOnHand") 
			return StockOnHand;
		if(propName == "Products") 
			return Products;
		return ExtendGetProperty(propName);
	}
	
	/// <summary>
    /// Sets the value associated with the propName parameter to the value specified.
    /// </summary>
    /// <param name="propName">String property name.</param>
    /// <param name="value">The value.</param>
	public override void SetProperty(string propName, object value)
	{
		if(propName == "InventoryID") 
		{
			InventoryID = (System.Guid?)value;
			return;
		}
		if(propName == "ProductID") 
		{
			ProductID = (System.Guid?)value;
			return;
		}
		if(propName == "StockOnHand") 
		{
			StockOnHand = (System.Int32?)value;
			return;
		}
		if(propName == "Products") 
		{
			Products = (Product)value;
			return;
		}
		ExtendSetProperty(propName, value);
	}


    /// <summary>
    /// Adds a set of facts for this instance to the list.
    /// </summary>
    /// <param name="list">The list.</param>
    /// <param name="parent">The parent.</param>
    protected override void MakeFacts(List<WME> list, string parent)
    {
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "InventoryID"), InventoryID));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "ProductID"), ProductID));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "StockOnHand"), StockOnHand));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "Products"), Products));
        ExtendMakeFacts(list, parent);
        myFactsHaveBeenAsserted = true;
    }

	/// <summary>
    /// Populates the EntityObject from the specified surrogate.
    /// </summary>
    /// <param name="surrogate">The surrogate.</param>
	public void Populate(InventorySurrogate surrogate)
	{
		ProductID = surrogate.ProductID;
		StockOnHand = surrogate.StockOnHand;
	}
}

#endregion

#region InventoryTemplate

/// <summary>
/// Generated table specific Query Template Class </summary>
/// <remarks> A Query Template for Inventory operations. </remarks>
public class InventoryTemplate : QueryTemplate
{

	/// <summary>
	/// Constructor </summary>
	/// <remarks> Public Constructor.</remarks>
	/// <param name="anEntityMap">IEntityMap instance.</param>
	public InventoryTemplate(IEntityMap anEntityMap) : base(anEntityMap)
	{
	}
	
	/// <summary>
	/// Property InventoryID -  $attributes.Description </summary>
	/// <remarks> Database Path: CRMSample.Inventory.InventoryID.</remarks>
	/// <value> System.Guid. </value>
	public System.Guid InventoryID
	{
		get { return (System.Guid)QueryValues["InventoryID"]; }
		set { QueryValues["InventoryID"] = value; }
	}

	/// <summary>
	/// Property ProductID -  $attributes.Description </summary>
	/// <remarks> Database Path: CRMSample.Inventory.ProductID.</remarks>
	/// <value> System.Guid. </value>
	public System.Guid ProductID
	{
		get { return (System.Guid)QueryValues["ProductID"]; }
		set { QueryValues["ProductID"] = value; }
	}

	/// <summary>
	/// Property StockOnHand -  $attributes.Description </summary>
	/// <remarks> Database Path: CRMSample.Inventory.StockOnHand.</remarks>
	/// <value> System.Int32. </value>
	public System.Int32 StockOnHand
	{
		get { return (System.Int32)QueryValues["StockOnHand"]; }
		set { QueryValues["StockOnHand"] = value; }
	}

	/// <summary>
	/// Property Products - gets or sets the Product object with a one-to-one relationship to this instance.</summary>
	/// <remarks> Gets or sets the Product object.</remarks>
	/// <value> Product. </value>
	public Product Products
	{
		get { return (Product)QueryValues["Products"]; }
		set { QueryValues["Products"] = value; }
	}

               
}

#endregion

#region InventoryFactory

/// <summary>
/// Factory class for the creation of Inventory objects.</summary>
/// <remarks> This class is generated by the Neo Framework. Make changes to NeoSupport.vtl.</remarks>
public class InventoryFactory : Neo.Framework.ObjectFactory
{

	/// <summary>
	/// Constructor requiring an ObjectContext parameter.</summary>
	/// <remarks> Main entry point for the retrieval and creation of new Inventory objects.</remarks>
	/// <param name="context">ObjectContext.</param>
	public InventoryFactory(ObjectContext context) : base(context, typeof(Inventory))
	{
	}

	/// <summary>
	/// Create new Inventory object.</summary>
	/// <remarks>IdMethod = Guid, PrimaryKeyIsForeignKey = False, RelationshipSetsForColumns = 0.</remarks>
	/// <returns> Inventory </returns>
	public Inventory CreateObject()
	{
		return (Inventory)base.CreateObject(null);
	}
	

	/// <summary>
	/// Find a specified Inventory object.</summary>
	/// <remarks> Requires Primary Key values and/or parent object instances.</remarks>
	/// <param name="arg0">$column.Description.</param>
	/// <returns> Inventory </returns>
	public Inventory FindObject(System.Guid arg0)
	{
		return (Inventory)base.FindObject(new object[] { arg0 } );
	}

	///<summary>
	///Find a specified Inventory object.</summary>
	///<remarks> Requires Primary Key values and/or parent object instances.</remarks>
	///<param name="arg0">$column.Description.</param>
	///<returns> Inventory </returns>
	public Inventory FindObjectByPK( System.Guid arg0 )
	{
		return (Inventory) base.FindObject( new object[] {  arg0 } );
	}
	

	///<summary>
	///Find a specified Inventory object.</summary>
	///<remarks> Requires Primary Key values and/or parent object instances.</remarks>
	///<param name="arg0">$column.Description.</param>
	///<returns> Inventory </returns>
	public Inventory FindObjectByPK( System.Guid? arg0 )
	{
		return (Inventory) base.FindObject( new object[] {  arg0.Value } );
	}

	/// <summary>
	/// Find a list of Inventory objects.</summary>
	/// <remarks> Returns all.</remarks>
	/// <returns> ObjectList&lt;Inventory&gt; </returns>
	public new ObjectList<Inventory> FindAllObjects()
	{
		ObjectList<Inventory> c = new ObjectList<Inventory>();
		foreach(Inventory eo in base.FindAllObjects())
			c.Add(eo);
		return c;
	}
	
	/// <summary>
	/// Return the correct Query Template for the Inventory object.</summary>
	/// <remarks> A query template is used for creating SQL like queries, in a more OO fashion.</remarks>
	/// <returns> InventoryTemplate </returns>
	public InventoryTemplate GetQueryTemplate()
	{
		return new InventoryTemplate(EntityMap);
	}
	
	/// <summary>
	/// SQL like query to find and return a list of objects based on a template.</summary>
	/// <remarks> A query template is used for creating SQL like queries, in a more OO fashion.</remarks>
	/// <param name="template">InventoryTemplate.</param>
	/// <returns> ObjectList&lt;Inventory&gt; </returns>
	public ObjectList<Inventory> Find(InventoryTemplate template)
	{
		ObjectList<Inventory> c = new ObjectList<Inventory>();
		foreach(Inventory eo in base.Find(template))
			c.Add(eo);
		return c;
	}

	/// <summary>
	/// SQL like query to find and return a list of objects based on a FetchSpecification.</summary>
	/// <remarks> A query Fetch Specification is used for creating SQL like queries, in a more OO fashion.</remarks>
	/// <param name="fetchSpecification">FetchSpecification.</param>
	/// <returns> ObjectList&lt;Inventory&gt; </returns>
	public ObjectList<Inventory> Find(FetchSpecification fetchSpecification)
	{
		ObjectList<Inventory> c = new ObjectList<Inventory>();
		foreach(Inventory eo in base.Find(fetchSpecification))
			c.Add(eo);
		return c;
	}
	
	/// <summary>
	/// SQL like query to find and return a list of objects.</summary>
	/// <remarks> For example: ...Find("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> ObjectList&lt;Inventory&gt; </returns>
	public new ObjectList<Inventory> Find(string qualifierFormat, params object[] parameters)
	{
		ObjectList<Inventory> c = new ObjectList<Inventory>();
		foreach(Inventory eo in base.Find(qualifierFormat, parameters))
			c.Add(eo);
		return c;
	}

	/// <summary>
	/// SQL like query to find and return a list of objects limiting the munber of items returned.</summary>
	/// <remarks> For example: ...Find(10, "TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="limit">Int32.</param>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> ObjectList&lt;Inventory&gt; </returns>
	public new ObjectList<Inventory> FindWithLimit(int limit, string qualifierFormat, params object[] parameters)
	{
		ObjectList<Inventory> c = new ObjectList<Inventory>();
		foreach(Inventory eo in base.Find(qualifierFormat, parameters))
			c.Add(eo);
		return c;
	}
	
	/// <summary>
	/// SQL like query to find and return an object.</summary>
	/// <remarks> For example: ...FindFirst("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> Inventory. </returns>
	public new Inventory FindFirst(string qualifierFormat, params object[] parameters)
	{
		return (Inventory)base.FindFirst(qualifierFormat, parameters);
	}

	/// <summary>
	/// SQL like query to find and return an object.</summary>
	/// <remarks> For example: ...FindUnique("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> Inventory. </returns>
	public new Inventory FindUnique(string qualifierFormat, params object[] parameters)
	{
		return (Inventory)base.FindUnique(qualifierFormat, parameters);
	}	

	
}

#endregion

#region InventoryEntityMap

//  -------- Entity Map -----------------------------------------------------
/// <summary>Creates the in memory version of the dataset for the Inventory DOM.</summary>
/// <remarks>Generated by Neo Framework.</remarks>
internal class InventoryMap : EntityMap
{
	  /// <summary>Array of Primary Key column names.</summary>
	  /// <remarks>Primary Key columns.</remarks>
    private static readonly string[] pkcolumns = { "InventoryID" };
    /// <summary>Array of Database column names.</summary>
	  /// <remarks>Database column names.</remarks>
    private static readonly string[] columns = { "InventoryID", "ProductID", "StockOnHand" };
    /// <summary>Array of DOM object properties.</summary>
	  /// <remarks>DOM object properties.</remarks>
    private static readonly string[] attributes = { "InventoryID", "ProductID", "StockOnHand" };
    /// <summary>Array of Related Object names.</summary>
	  /// <remarks>Related Object names.</remarks>
    private static readonly string[] relations = { "Products" };

    private Type concreteObjectType = typeof(Inventory);

	  /// <summary>Property ObjectType.</summary>
	  /// <remarks>Returns the DOM's Type.</remarks>
	  /// <value>System.Type.</value>
    public override System.Type ObjectType
    {
        get { return typeof(Inventory); }
    }
    
    /// <summary>Property ObjectType.</summary>
	  /// <remarks>Returns the DOM's Type.</remarks>
	  /// <value>System.Type.</value>
    public override System.Type ConcreteObjectType
    {
        get { return concreteObjectType; }										 /* #custom# overridden */
        set { concreteObjectType = value; Factory.AddCustomType(value, this); }  /* #custom# overridden */
    }
    
    /// <summary>Property TableName.</summary>
	  /// <remarks>Returns database table name.</remarks>
	  /// <value>string.</value>
    public override string TableName
    {
        get { return "Inventory"; }
    }
    
    /// <summary>Property PrimaryKeyColumns.</summary>
	/// <remarks>Array of Primary Key column names.</remarks>
	/// <value>string[].</value>
    public override string[] PrimaryKeyColumns
    {
        get { return pkcolumns; }
    }

	/// <summary>Property Columns.</summary>
	/// <remarks>Array of Database column names.</remarks>
	/// <value>string[].</value>
    public override string[] Columns
    {
        get { return columns; }
    }

	/// <summary>Property Attributes.</summary>
	/// <remarks>Array of DOM object properties.</remarks>
	/// <value>string[].</value>
    public override string[] Attributes
    {
        get { return attributes; }
    }

    /// <summary>Property Relations.</summary>
	/// <remarks>Array of Related Object names.</remarks>
	/// <value>string[].</value>
    public override string[] Relations
    {
        get { return relations; }
    }

	/// <summary>Generates a Hashtable, keyed by Object Name, or information regarding related objects.</summary>
	/// <remarks>Related Objects.</remarks>
	/// <returns>IDictionary.</returns>
  	protected override IDictionary GetRelationInfos()
    {
    	IDictionary infos = new Hashtable(1);
  		infos.Add("Products", new RelationInfo(Factory, typeof(Product), typeof(Inventory), "ProductID", "ProductID"));
		return infos;    	
    }
    
	/// <summary>Based upon the model specified Id Method, returns the proper PkInitializer.</summary>
	/// <remarks>The object used to create a new PK value.</remarks>
	/// <returns>IPkInitializer.</returns>
	public override IPkInitializer GetPkInitializer()
	{
		return new GuidPkInitializer();
	}
    
	/// <summary>Creates a new instance of Inventory.</summary>
	/// <remarks>Create new Inventory.</remarks>
	/// <param name="row">DataRow.</param>
	/// <param name="context">ObjectContext.</param>
	/// <returns>IEntityObject.</returns>
    public override IEntityObject CreateInstance(DataRow row, ObjectContext context) /* #custom# overridden */
    {
		if(ConcreteObjectType != ObjectType)
			return base.CreateInstance(row, context);
		return new Inventory(row, context);
	}
    
    /// <summary>Generates the in memory dataset.</summary>
	/// <remarks>Called by the Factory object.</remarks>
	/// <param name="table">DataTable.</param>
    protected override void WriteBasicSchema(DataTable table)
    {
		DataColumn		c;
		
		c = table.Columns.Add("InventoryID", typeof(System.Guid));
		c.Unique = true;
		c = table.Columns.Add("ProductID", typeof(System.Guid));
		c = table.Columns.Add("StockOnHand", typeof(System.Int32));
		table.PrimaryKey = new DataColumn[] { table.Columns["InventoryID"] };
	}
	
	/// <summary>Generates the dataset relationships.</summary>
	/// <remarks>Dataset Relationships.</remarks>
	/// <param name="table">DataTable.</param>
	protected override void WriteRelations(DataTable table)
	{
		DataRelation r;
		
		if(table.DataSet.Relations["Products*Inventory.ProductID"] == null)
		{
			r = table.DataSet.Relations.Add("Products*Inventory.ProductID", 
					table.DataSet.Tables["Products"].Columns["ProductID"],
					table.DataSet.Tables["Inventory"].Columns["ProductID"]);
			r.ChildKeyConstraint.UpdateRule = Rule.None;
			r.ChildKeyConstraint.DeleteRule = Rule.None;
		}
	}
}

#endregion

#region InventorySurrogateBase

/// <summary>Represents an entity object disconnected from the database.</summary>
/// <remarks>
///   <para>Database Path: CRMSample.Inventory.</para>
/// </remarks>
[Serializable]
public abstract class InventorySurrogateBase : EntityObjectSurrogate
{
    /// <summary>Default constructor.</summary>
    public InventorySurrogateBase()
    {
    }
    
    /// <summary>
    /// Initializes a new instance of the <see cref="InventorySurrogateBase"/> class.
    /// </summary>
    /// <param name="entity">The entity.</param>
    public InventorySurrogateBase(Inventory entity)
    {
		InventoryID = entity.InventoryID;
		ProductID = entity.ProductID;
		StockOnHand = entity.StockOnHand;
    }
    
    /// <summary>
    /// Updates the entity with the values contained within the surrogate.
    /// </summary>
    /// <param name="entity">The entity.</param>
    public void BindObjectInstance(Inventory entity)
    {
		if (entity.Row.RowState == DataRowState.Added)
        {
			entity.ProductID = ProductID;
			entity.StockOnHand = StockOnHand;
		}
		else
		{
			if (_productidHasBeenUpdated)
			{
				entity.ProductID = ProductID;
			}
			if (_stockonhandHasBeenUpdated)
			{
				entity.StockOnHand = StockOnHand;
			}
		}
    }
    
	/// <summary>
    /// Property InventoryID -  $attribute.Description </summary>
    /// <remarks> Database Path: CRMSample.Inventory.InventoryID.</remarks>
    /// <value> System.Guid. </value>
    public System.Guid? InventoryID
    {
    	get {return _inventoryid;}
		set {_inventoryid = value;}
    }

	private System.Guid? _inventoryid;
	
	/// <summary>
    /// Property ProductID -  $attribute.Description </summary>
    /// <remarks> Database Path: CRMSample.Inventory.ProductID.</remarks>
    /// <value> System.Guid. </value>
    public System.Guid? ProductID
    {
    	get {return _productid;}
    	set {_productid = value; _productidHasBeenUpdated = true;}
    }

	private System.Guid? _productid;
    private bool _productidHasBeenUpdated;
	
	/// <summary>
    /// Property StockOnHand -  $attribute.Description </summary>
    /// <remarks> Database Path: CRMSample.Inventory.StockOnHand.</remarks>
    /// <value> System.Int32. </value>
    public System.Int32? StockOnHand
    {
    	get {return _stockonhand;}
    	set {_stockonhand = value; _stockonhandHasBeenUpdated = true;}
    }

	private System.Int32? _stockonhand;
    private bool _stockonhandHasBeenUpdated;
	
    /// <summary>
    /// Property Products - gets or sets the Product object with a one-to-one relationship to this instance.</summary>
    /// <remarks> Property Products - gets or sets the Product object with a one-to-one relationship to this instance.</remarks>
    /// <value> Product. </value>
    public ProductSurrogate Products
    {
    	get {return _products;}
    	set {_products = value;}
    }

	private ProductSurrogate _products;
		

	/// <summary>
    /// Binds the surrogate values to the search template.
    /// </summary>
    /// <param name="emptyTemplate">The empty template.</param>
	public void BindToSearchTemplate(InventoryTemplate emptyTemplate)
    {
        if (this.ProductID != null)
            emptyTemplate.ProductID = this.ProductID.Value;
    }
    
	/// <summary>
	/// Determines whether this instance is valid.
	/// </summary>
	/// <returns>
	///	<c>true</c> if this instance is valid; otherwise, <c>false</c>.
	/// </returns>
    public abstract bool IsValid();

	/// <summary>
	/// Gets the validation message.
	/// </summary>
	/// <value>The validation message.</value>
    public abstract String ValidationMessage{get;}

}
#endregion

}

/* This is a customised template.
 * It overrides some optional methods from EntityMap to allow for testing 
 * with Mocks and fast object creation. Search for #custom# below. 
 */


namespace CRMSample.Models
{

#region Using statements

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using Neo.Core;
using Expergent;
using Expergent.Neo;
using Neo.Core.Util;
using Neo.Framework;

#endregion

#region StatusBase

/// <summary>
/// Generated table specific Base Class </summary>
/// <remarks> This class is generated by the Neo Framework. Make changes to NeoSupport.vtl.</remarks>
public partial class Status : RulesEnabledEntityObject
{
	/// <summary>
	/// A collection of Customer objects referencing this instance.</summary>
	/// <remarks> Objects referencing this instance.</remarks>
	public readonly ObjectRelation<Customer> Customers;
       
	internal Status(System.Data.DataRow aRow, Neo.Core.ObjectContext aContext) : base(aRow, aContext)
	{
		Customers = new ObjectRelation<Customer>(this, "Customers");
	}
	
	/// <summary>
	/// Property StatusID -  $attribute.Description </summary>
	/// <remarks> Database Path: CRMSample.Status.StatusID.</remarks>
	/// <value> System.Int32. </value>
	public virtual System.Int32? StatusID
	{
		get { object v = Row["StatusID"]; return (System.Int32?)((v != DBNull.Value) ? v : null); }
		set { if (value.HasValue) Row["StatusID"] = value; else Row["StatusID"] = DBNull.Value; }
	}    

	/// <summary>
	/// Property Name -  $attribute.Description </summary>
	/// <remarks> Database Path: CRMSample.Status.Name.</remarks>
	/// <value> System.String. </value>
	public virtual System.String Name
	{
		get { return Row["Name"] as System.String; }
		set { Row["Name"] = (value != null) ? (object)value : (object)DBNull.Value; }
	}    


	/// <summary>
	/// Returns the value associated with the propName parameter.</summary>
	/// <remarks> You will need to cast the returned object into its native type upon return.</remarks>
	/// <param name="propName">String property name.</param>
	/// <returns> System.Object. </returns>
	public override object GetProperty(string propName)
	{
		if(propName == "StatusID") 
			return StatusID;
		if(propName == "Name") 
			return Name;
		if(propName == "Customers") 
			return Customers;
		return ExtendGetProperty(propName);
	}
	
	/// <summary>
    /// Sets the value associated with the propName parameter to the value specified.
    /// </summary>
    /// <param name="propName">String property name.</param>
    /// <param name="value">The value.</param>
	public override void SetProperty(string propName, object value)
	{
		if(propName == "StatusID") 
		{
			StatusID = (System.Int32?)value;
			return;
		}
		if(propName == "Name") 
		{
			Name = (System.String)value;
			return;
		}
		ExtendSetProperty(propName, value);
	}

    /// <summary>
    /// Ensures related tables are loaded into memory for a cascaded delete.</summary>
    /// <remarks> Deletes related tables entries when cascade is specified.</remarks>
    public override void Delete() 
    {
        Customers.Touch();
        while (Customers.Count > 0)
        {
            Customers[0].Delete();
        }
        base.Delete();
    }

    /// <summary>
    /// Adds a set of facts for this instance to the list.
    /// </summary>
    /// <param name="list">The list.</param>
    /// <param name="parent">The parent.</param>
    protected override void MakeFacts(List<WME> list, string parent)
    {
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "StatusID"), StatusID));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "Name"), Name));
        list.Add(new WME(new EntityObjectTerm(this), MakePredicate(parent, "Customers"), Customers));
        ExtendMakeFacts(list, parent);
        myFactsHaveBeenAsserted = true;
    }

	/// <summary>
    /// Populates the EntityObject from the specified surrogate.
    /// </summary>
    /// <param name="surrogate">The surrogate.</param>
	public void Populate(StatusSurrogate surrogate)
	{
		Name = surrogate.Name;
	}
}

#endregion

#region StatusTemplate

/// <summary>
/// Generated table specific Query Template Class </summary>
/// <remarks> A Query Template for Status operations. </remarks>
public class StatusTemplate : QueryTemplate
{

	/// <summary>
	/// Constructor </summary>
	/// <remarks> Public Constructor.</remarks>
	/// <param name="anEntityMap">IEntityMap instance.</param>
	public StatusTemplate(IEntityMap anEntityMap) : base(anEntityMap)
	{
	}
	
	/// <summary>
	/// Property StatusID -  $attributes.Description </summary>
	/// <remarks> Database Path: CRMSample.Status.StatusID.</remarks>
	/// <value> System.Int32. </value>
	public System.Int32 StatusID
	{
		get { return (System.Int32)QueryValues["StatusID"]; }
		set { QueryValues["StatusID"] = value; }
	}

	/// <summary>
	/// Property Name -  $attributes.Description </summary>
	/// <remarks> Database Path: CRMSample.Status.Name.</remarks>
	/// <value> System.String. </value>
	public System.String Name
	{
		get { return (System.String)QueryValues["Name"]; }
		set { QueryValues["Name"] = value; }
	}

               
}

#endregion

#region StatusFactory

/// <summary>
/// Factory class for the creation of Status objects.</summary>
/// <remarks> This class is generated by the Neo Framework. Make changes to NeoSupport.vtl.</remarks>
public class StatusFactory : Neo.Framework.ObjectFactory
{

	/// <summary>
	/// Constructor requiring an ObjectContext parameter.</summary>
	/// <remarks> Main entry point for the retrieval and creation of new Status objects.</remarks>
	/// <param name="context">ObjectContext.</param>
	public StatusFactory(ObjectContext context) : base(context, typeof(Status))
	{
	}

	/// <summary>
	/// Create new Status object.</summary>
	/// <remarks>IdMethod = Native, PrimaryKeyIsForeignKey = False, RelationshipSetsForColumns = 1.</remarks>
	/// <returns> Status </returns>
	public Status CreateObject()
	{
		return (Status)base.CreateObject(null);
	}
	

	/// <summary>
	/// Find a specified Status object.</summary>
	/// <remarks> Requires Primary Key values and/or parent object instances.</remarks>
	/// <param name="arg0">$column.Description.</param>
	/// <returns> Status </returns>
	public Status FindObject(System.Int32 arg0)
	{
		return (Status)base.FindObject(new object[] { arg0 } );
	}

	///<summary>
	///Find a specified Status object.</summary>
	///<remarks> Requires Primary Key values and/or parent object instances.</remarks>
	///<param name="arg0">$column.Description.</param>
	///<returns> Status </returns>
	public Status FindObjectByPK( System.Int32 arg0 )
	{
		return (Status) base.FindObject( new object[] {  arg0 } );
	}
	

	///<summary>
	///Find a specified Status object.</summary>
	///<remarks> Requires Primary Key values and/or parent object instances.</remarks>
	///<param name="arg0">$column.Description.</param>
	///<returns> Status </returns>
	public Status FindObjectByPK( System.Int32? arg0 )
	{
		return (Status) base.FindObject( new object[] {  arg0.Value } );
	}

	/// <summary>
	/// Find a list of Status objects.</summary>
	/// <remarks> Returns all.</remarks>
	/// <returns> ObjectList&lt;Status&gt; </returns>
	public new ObjectList<Status> FindAllObjects()
	{
		ObjectList<Status> c = new ObjectList<Status>();
		foreach(Status eo in base.FindAllObjects())
			c.Add(eo);
		return c;
	}
	
	/// <summary>
	/// Return the correct Query Template for the Status object.</summary>
	/// <remarks> A query template is used for creating SQL like queries, in a more OO fashion.</remarks>
	/// <returns> StatusTemplate </returns>
	public StatusTemplate GetQueryTemplate()
	{
		return new StatusTemplate(EntityMap);
	}
	
	/// <summary>
	/// SQL like query to find and return a list of objects based on a template.</summary>
	/// <remarks> A query template is used for creating SQL like queries, in a more OO fashion.</remarks>
	/// <param name="template">StatusTemplate.</param>
	/// <returns> ObjectList&lt;Status&gt; </returns>
	public ObjectList<Status> Find(StatusTemplate template)
	{
		ObjectList<Status> c = new ObjectList<Status>();
		foreach(Status eo in base.Find(template))
			c.Add(eo);
		return c;
	}

	/// <summary>
	/// SQL like query to find and return a list of objects based on a FetchSpecification.</summary>
	/// <remarks> A query Fetch Specification is used for creating SQL like queries, in a more OO fashion.</remarks>
	/// <param name="fetchSpecification">FetchSpecification.</param>
	/// <returns> ObjectList&lt;Status&gt; </returns>
	public ObjectList<Status> Find(FetchSpecification fetchSpecification)
	{
		ObjectList<Status> c = new ObjectList<Status>();
		foreach(Status eo in base.Find(fetchSpecification))
			c.Add(eo);
		return c;
	}
	
	/// <summary>
	/// SQL like query to find and return a list of objects.</summary>
	/// <remarks> For example: ...Find("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> ObjectList&lt;Status&gt; </returns>
	public new ObjectList<Status> Find(string qualifierFormat, params object[] parameters)
	{
		ObjectList<Status> c = new ObjectList<Status>();
		foreach(Status eo in base.Find(qualifierFormat, parameters))
			c.Add(eo);
		return c;
	}

	/// <summary>
	/// SQL like query to find and return a list of objects limiting the munber of items returned.</summary>
	/// <remarks> For example: ...Find(10, "TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="limit">Int32.</param>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> ObjectList&lt;Status&gt; </returns>
	public new ObjectList<Status> FindWithLimit(int limit, string qualifierFormat, params object[] parameters)
	{
		ObjectList<Status> c = new ObjectList<Status>();
		foreach(Status eo in base.Find(qualifierFormat, parameters))
			c.Add(eo);
		return c;
	}
	
	/// <summary>
	/// SQL like query to find and return an object.</summary>
	/// <remarks> For example: ...FindFirst("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> Status. </returns>
	public new Status FindFirst(string qualifierFormat, params object[] parameters)
	{
		return (Status)base.FindFirst(qualifierFormat, parameters);
	}

	/// <summary>
	/// SQL like query to find and return an object.</summary>
	/// <remarks> For example: ...FindUnique("TitleAuthors.(Title = {0} or Title.Publisher = {1})", title, publisher).</remarks>
	/// <param name="qualifierFormat">String.</param>
	/// <param name="parameters">params object[].</param>
	/// <returns> Status. </returns>
	public new Status FindUnique(string qualifierFormat, params object[] parameters)
	{
		return (Status)base.FindUnique(qualifierFormat, parameters);
	}	

	
}

#endregion

#region StatusEntityMap

//  -------- Entity Map -----------------------------------------------------
/// <summary>Creates the in memory version of the dataset for the Status DOM.</summary>
/// <remarks>Generated by Neo Framework.</remarks>
internal class StatusMap : EntityMap
{
	  /// <summary>Array of Primary Key column names.</summary>
	  /// <remarks>Primary Key columns.</remarks>
    private static readonly string[] pkcolumns = { "StatusID" };
    /// <summary>Array of Database column names.</summary>
	  /// <remarks>Database column names.</remarks>
    private static readonly string[] columns = { "StatusID", "Name" };
    /// <summary>Array of DOM object properties.</summary>
	  /// <remarks>DOM object properties.</remarks>
    private static readonly string[] attributes = { "StatusID", "Name" };
    /// <summary>Array of Related Object names.</summary>
	  /// <remarks>Related Object names.</remarks>
    private static readonly string[] relations = { "Customers" };

    private Type concreteObjectType = typeof(Status);

	  /// <summary>Property ObjectType.</summary>
	  /// <remarks>Returns the DOM's Type.</remarks>
	  /// <value>System.Type.</value>
    public override System.Type ObjectType
    {
        get { return typeof(Status); }
    }
    
    /// <summary>Property ObjectType.</summary>
	  /// <remarks>Returns the DOM's Type.</remarks>
	  /// <value>System.Type.</value>
    public override System.Type ConcreteObjectType
    {
        get { return concreteObjectType; }										 /* #custom# overridden */
        set { concreteObjectType = value; Factory.AddCustomType(value, this); }  /* #custom# overridden */
    }
    
    /// <summary>Property TableName.</summary>
	  /// <remarks>Returns database table name.</remarks>
	  /// <value>string.</value>
    public override string TableName
    {
        get { return "Status"; }
    }
    
    /// <summary>Property PrimaryKeyColumns.</summary>
	/// <remarks>Array of Primary Key column names.</remarks>
	/// <value>string[].</value>
    public override string[] PrimaryKeyColumns
    {
        get { return pkcolumns; }
    }

	/// <summary>Property Columns.</summary>
	/// <remarks>Array of Database column names.</remarks>
	/// <value>string[].</value>
    public override string[] Columns
    {
        get { return columns; }
    }

	/// <summary>Property Attributes.</summary>
	/// <remarks>Array of DOM object properties.</remarks>
	/// <value>string[].</value>
    public override string[] Attributes
    {
        get { return attributes; }
    }

    /// <summary>Property Relations.</summary>
	/// <remarks>Array of Related Object names.</remarks>
	/// <value>string[].</value>
    public override string[] Relations
    {
        get { return relations; }
    }

	/// <summary>Generates a Hashtable, keyed by Object Name, or information regarding related objects.</summary>
	/// <remarks>Related Objects.</remarks>
	/// <returns>IDictionary.</returns>
  	protected override IDictionary GetRelationInfos()
    {
    	IDictionary infos = new Hashtable(1);
  		infos.Add("Customers", new RelationInfo(Factory, typeof(Status), typeof(Customer), "StatusID", "StatusID"));
		return infos;    	
    }
    
	/// <summary>Based upon the model specified Id Method, returns the proper PkInitializer.</summary>
	/// <remarks>The object used to create a new PK value.</remarks>
	/// <returns>IPkInitializer.</returns>
	public override IPkInitializer GetPkInitializer()
	{
		return new NativePkInitializer();
	}
    
	/// <summary>Creates a new instance of Status.</summary>
	/// <remarks>Create new Status.</remarks>
	/// <param name="row">DataRow.</param>
	/// <param name="context">ObjectContext.</param>
	/// <returns>IEntityObject.</returns>
    public override IEntityObject CreateInstance(DataRow row, ObjectContext context) /* #custom# overridden */
    {
		if(ConcreteObjectType != ObjectType)
			return base.CreateInstance(row, context);
		return new Status(row, context);
	}
    
    /// <summary>Generates the in memory dataset.</summary>
	/// <remarks>Called by the Factory object.</remarks>
	/// <param name="table">DataTable.</param>
    protected override void WriteBasicSchema(DataTable table)
    {
		DataColumn		c;
		
		c = table.Columns.Add("StatusID", typeof(System.Int32));
		c.Unique = true;
		c.AutoIncrement = true; c.AutoIncrementSeed = c.AutoIncrementStep = -1;
		c = table.Columns.Add("Name", typeof(System.String));
		table.PrimaryKey = new DataColumn[] { table.Columns["StatusID"] };
	}
	
	/// <summary>Generates the dataset relationships.</summary>
	/// <remarks>Dataset Relationships.</remarks>
	/// <param name="table">DataTable.</param>
	protected override void WriteRelations(DataTable table)
	{
		DataRelation r;
		
 		if(table.DataSet.Relations["Status*Customers.StatusID"] == null)
		{
			r = table.DataSet.Relations.Add("Status*Customers.StatusID", 
					table.DataSet.Tables["Status"].Columns["StatusID"],
					table.DataSet.Tables["Customers"].Columns["StatusID"]);
			r.ChildKeyConstraint.UpdateRule = Rule.None;
			r.ChildKeyConstraint.DeleteRule = Rule.None;
		}
	}
}

#endregion

#region StatusSurrogateBase

/// <summary>Represents an entity object disconnected from the database.</summary>
/// <remarks>
///   <para>Database Path: CRMSample.Status.</para>
/// </remarks>
[Serializable]
public abstract class StatusSurrogateBase : EntityObjectSurrogate
{
    /// <summary>Default constructor.</summary>
    public StatusSurrogateBase()
    {
    }
    
    /// <summary>
    /// Initializes a new instance of the <see cref="StatusSurrogateBase"/> class.
    /// </summary>
    /// <param name="entity">The entity.</param>
    public StatusSurrogateBase(Status entity)
    {
		StatusID = entity.StatusID;
		Name = entity.Name;
    }
    
    /// <summary>
    /// Updates the entity with the values contained within the surrogate.
    /// </summary>
    /// <param name="entity">The entity.</param>
    public void BindObjectInstance(Status entity)
    {
		if (entity.Row.RowState == DataRowState.Added)
        {
			entity.Name = Name;
		}
		else
		{
			if (_nameHasBeenUpdated)
			{
				entity.Name = Name;
			}
		}
    }
    
    /// <summary>
    /// Property Customers </summary>
    /// <remarks> </remarks>
    /// <value> System.Collections.ArrayList </value>
    public System.Collections.ArrayList Customers
    {
    	get {return _customers;}
    	set {_customers = value;}
    }
		
	private System.Collections.ArrayList _customers;
	
	/// <summary>
    /// Property StatusID -  $attribute.Description </summary>
    /// <remarks> Database Path: CRMSample.Status.StatusID.</remarks>
    /// <value> System.Int32. </value>
    public System.Int32? StatusID
    {
    	get {return _statusid;}
		set {_statusid = value;}
    }

	private System.Int32? _statusid;
	
    /// <summary>
    /// Property Name -  $attribute.Description </summary>
    /// <remarks> Database Path: CRMSample.Status.Name.</remarks>
    /// <value> System.String. </value>
    public System.String Name
    {
    	get {return _name;}
    	set {_name = value; _nameHasBeenUpdated = true;}
    }

	private System.String _name;
    private bool _nameHasBeenUpdated;
	

	/// <summary>
    /// Binds the surrogate values to the search template.
    /// </summary>
    /// <param name="emptyTemplate">The empty template.</param>
	public void BindToSearchTemplate(StatusTemplate emptyTemplate)
    {
    }
    
	/// <summary>
	/// Determines whether this instance is valid.
	/// </summary>
	/// <returns>
	///	<c>true</c> if this instance is valid; otherwise, <c>false</c>.
	/// </returns>
    public abstract bool IsValid();

	/// <summary>
	/// Gets the validation message.
	/// </summary>
	/// <value>The validation message.</value>
    public abstract String ValidationMessage{get;}

}
#endregion

}

